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



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

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

Class Method Details

.supported?Boolean

Returns:

  • (Boolean)


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

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)


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

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

#requestObject

Request the animation frame.

Raises:

  • (NotImplementedError)


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

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