W3cubDocs

/DOM

window.cancelAnimationFrame

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) {
    myReq = requestAnimationFrame(step);
  }
}
myReq = requestAnimationFrame(step);

cancelAnimationFrame(myReq);

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support Yes Yes 23
23
11 — 23
Prefixed
Prefixed Requires the vendor prefix: moz
10 15 6.1
6.1
6 — 6.1
Prefixed
Prefixed Requires the vendor prefix: webkit
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support Yes Yes Yes 23
23
14 — 23
Prefixed
Prefixed Requires the vendor prefix: moz
33 7.1 ?

Specification

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/window/cancelAnimationFrame