Web APIs

requestAnimationFrame()

Try the free JavaScript compiler

Requests a callback during a browser animation-frame update before the associated repaint opportunity. Callback receives a timestamp; cadence is not guaranteed. Multi-file example: save each listed file separately, then serve the entry over local HTTP in a browser. See the packaged fixture for the original files.

Formal Syntax & Structure

javascript syntaxjavascript
requestAnimationFrame(callback)

Parameters & Attributes

NameTypeDescription
callbackfunctionReceives the animation frame timestamp.

Return Value

number

Request identifier usable for cancellation.

Working Example

Example Snippetjavascript
// File: index.html<!doctype html><meta charset="utf-8"><title>Frame</title><p id="out">start</p><script>requestAnimationFrame(()=>{document.getElementById("out").textContent="updated";console.log("frame");});console.log("script");</script>
JavaScript Reference