requestAnimationFrame method
@AvailableInWorkers("dedicated")
The requestAnimationFrame()
method of the
DedicatedWorkerGlobalScope interface tells the browser you wish to
perform an animation frame request and 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 60 Hz, (60
cycles/frames per second), though 75 Hz, 120 Hz, and 144 Hz are also
widely used. requestAnimationFrame()
calls are paused in most browsers
when running in background tabs or hidden iframe
s, to improve
performance and battery life.
A call to the requestAnimationFrame()
method schedules only one single
call to the callback function. If you want to animate another frame, your
callback function must call requestAnimationFrame()
again.
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.
Calling the requestAnimationFrame()
method requires the current worker
to have an associated owner Window. That means that the current worker
must be created by Window or by a dedicated worker that also has an
associated owner Window.
Implementation
external int requestAnimationFrame(FrameRequestCallback callback);