Class: Browser::AnimationFrame

Inherits:
Object
  • Object
show all
Defined in:
opal/browser/animation_frame.rb

Overview

Allows you to wrap a block to use in an animation rendering cycle.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window, &block) ⇒ AnimationFrame

Execute the block to update an animation before the next repaint.

Parameters:

  • window (Window)

    the window to request the frame on



21
22
23
24
25
# File 'opal/browser/animation_frame.rb', line 21

def initialize(window, &block)
  @window = window
  @native = window.to_n
  @id     = request(block)
end

Class Method Details

.supported?Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
# File 'opal/browser/animation_frame.rb', line 8

def self.supported?
  ['Animation.request',
   'Animation.request (Chrome)',
   'Animation.request (Firefox)',
   'Animation.request (Opera)',
   'Animation.request (Internet Explorer)'].any? {|feature|
     Browser.supports? feature
   }
end

Instance Method Details

#cancelObject

Cancel the animation frame request.

Raises:

  • (NotImplementedError)


92
93
94
# File 'opal/browser/animation_frame.rb', line 92

def cancel
  `#@native.cancelAnimationFrame(#@id)`
end

#requestObject

Request the animation frame.

Raises:

  • (NotImplementedError)


49
50
51
# File 'opal/browser/animation_frame.rb', line 49

def request(block)
  `#@native.requestAnimationFrame(#{block.to_n})`
end