requestAnimationFrame method
The window.requestAnimationFrame()
method tells the
browser you wish to perform an animation. It requests the browser to call
a
user-supplied callback function before the next repaint.
The frequency of calls to the callback function will generally match the
display
refresh rate. The most common refresh rate is 60hz,
(60 cycles/frames per second), though 75hz, 120hz, and 144hz are also
widely used.
requestAnimationFrame()
calls are paused in most browsers when running
in
background tabs or hidden iframe
s, in order to improve
performance and battery life.
Note: Your callback function must call
requestAnimationFrame()
again if you want to animate another frame.requestAnimationFrame()
is one-shot.
Warning: Be sure always to use the first argument (or some other method for getting the current time) to calculate how much the animation will progress in a frame — otherwise, the animation will run faster on high refresh-rate screens. For ways to do that, see the examples below.
Implementation
external int requestAnimationFrame(FrameRequestCallback callback);