The window.cancelAnimationFrame()
method cancels an animation frame request previously scheduled through a call to window.requestAnimationFrame()
.
Syntax
window.cancelAnimationFrame(requestID);
Parameters
requestID
- The ID value returned by the call to
window.requestAnimationFrame()
that requested the callback.
Examples
var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
var cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame;
var start = window.mozAnimationStartTime; // Only supported in FF. Other browsers can use something like Date.now().
var myReq;
function step(timestamp) {
var 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 cancelation uses the last requestId
cancelAnimationFrame(myReq);
Specifications
Specification | Status | Comment |
HTML Living StandardThe definition of 'cancelAnimationFrame()' in that specification. | Living Standard |
Browser compatibility
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.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
cancelAnimationFrame
|
Chrome
Full support 24 |
Edge
Full support 12 |
Firefox Full support 23 Full support 23 No support 11 — 23 Prefixed' Implemented with the vendor prefix: moz |
IE
Full support 10 |
Opera
Full support 15 |
Safari Full support 6.1 Full support 6.1 No support 6 — 6.1 Prefixed' Implemented with the vendor prefix: webkit |
WebView Android
Full support ≤37 |
Chrome Android
Full support 25 |
Firefox Android Full support 23 Full support 23 No support 14 — 23 Prefixed' Implemented with the vendor prefix: moz |
Opera Android
Full support 14 |
Safari iOS
Full support 7 |
Samsung Internet Android
Full support 1.5 |
Legend
- Full support
- Full support
- Requires a vendor prefix or different name for use.'
- Requires a vendor prefix or different name for use.
See also
window.cancelAnimationFrame() by Mozilla Contributors is licensed under CC-BY-SA 2.5.