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 compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support YesEdge Full support YesFirefox Full support 23
Full support 23
No support 11 — 23
Prefixed
Prefixed Requires the vendor prefix: moz
IE Full support 10Opera Full support 15Safari Full support 6.1
Full support 6.1
No support 6 — 6.1
Prefixed
Prefixed Requires the vendor prefix: webkit
WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 23
Full support 23
No support 14 — 23
Prefixed
Prefixed Requires the vendor prefix: moz
Opera Android Full support 33Safari iOS Full support 7.1Samsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

Specification

See also