Window: cancelAnimationFrame() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The window.cancelAnimationFrame()
method cancels an
animation frame request previously scheduled through a call to
window.requestAnimationFrame()
.
Syntax
js
cancelAnimationFrame(requestID)
Parameters
requestID
-
The ID value returned by the call to
window.requestAnimationFrame()
that requested the callback.
Return value
None (undefined
).
Examples
js
const start = document.timeline.currentTime;
let myReq;
function step(timestamp) {
const progress = timestamp - start;
d.style.left = `${Math.min(progress / 10, 200)}px`;
if (progress < 2000) {
// it's important to update the requestId each time you're calling requestAnimationFrame
myReq = requestAnimationFrame(step);
}
}
myReq = requestAnimationFrame(step);
// the cancellation uses the last requestId
cancelAnimationFrame(myReq);
Specifications
Specification |
---|
HTML # animationframeprovider-cancelanimationframe |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
cancelAnimationFrame |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Requires a vendor prefix or different name for use.
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.