CKTIS / JavaScript
requestAnimationFrame — updates before rendering
requestAnimationFrame requests a one-shot callback during a rendering update. It lets you animate using elapsed time rather than assuming a fixed number of frames per second.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
const handle = window.requestAnimationFrame((timestamp) => { /* update visual state */ });
window.cancelAnimationFrame(handle);window.requestAnimationFrame(callback) registers a one-shot callback that runs as part of a rendering update, before the image is presented. It returns a numeric request handle, not the callback's result. Request another frame explicitly to continue; window.cancelAnimationFrame(handle) removes a pending callback.
The timestamp argument is a high-resolution timestamp in milliseconds relative to the environment's time origin, not a calendar date or a frame duration. Calculate elapsed time by subtracting timestamps. Callbacks invoked in the same batch for the same target receive the same timestamp.
Do not assume 60 frames per second or a fixed delay. Frequency depends on rendering opportunities; invisible documents may receive no updates. Keep the callback short because lengthy work delays rendering. Time-based position changes prevent movement speed from depending on the frame count.
This is an HTML-standard API, not a feature of a particular ECMAScript edition. Current browser engines support it for Window; having Node 24 in a repository does not establish support. The example requires a visible page with an existing document.body. It animates a dot, and the final callback sets its translation to 100 pixels, logs done: 100px to the console, and removes the dot before the browser can paint it at that position. The intended movement duration is 1000 ms, but actual completion may occur later.
Examples
(() => {
const dot = document.createElement('div');
dot.textContent = '●';
document.body.append(dot);
let start;
function frame(timestamp) {
if (start === undefined) start = timestamp;
const progress = Math.min((timestamp - start) / 1000, 1);
dot.style.transform = `translateX(${100 * progress}px)`;
if (progress < 1) {
window.requestAnimationFrame(frame);
} else {
console.log('done: 100px');
dot.remove();
}
}
window.requestAnimationFrame(frame);
})();Result
done: 100px
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.