requestAnimationFrame()

Invoke the specified callback function at the next VSYNC.

requestAnimationFrame is typically used in scenarios where you want to achieve animation effects by modifying element attributes in each frame. Note that requestAnimationFrame will only take effect in the next frame; if you want it to continue to take effect, you need to nest requestAnimationFrame.

Syntax

requestAnimationFrame: (callback: (timeStamp: number) => void) => number;

Parameters

callback

The callback function that needs to be called at the next VSYNC. The callback function has one parameter timeStamp, which is the moment when the callback function starts to execute.

Return Value

An integer type id, used to cancel this requestAnimationFrame callback.

Examples

Print the frame rate in the console:

// Todo add example later

Compatibility

Loading

Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.