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

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
cancelAnimationFrame
Chrome – Full support
Chrome 24 (Release date: 2013-01-10)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – No support
Firefox 11 – 22 (Release date: 2012-03-13)
prefix
prefix Implemented with the vendor prefix: moz
Firefox – Full support
Firefox 23 (Release date: 2013-08-06)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – No support
Safari 6 – 6 (Release date: 2012-07-25)
prefix
prefix Implemented with the vendor prefix: webkit
Safari – Full support
Safari 7 (Release date: 2013-10-22)
footnote Full support
Chrome Android – Full support
Chrome Android 25 (Release date: 2013-02-27)
footnote Full support
Firefox for Android – No support
Firefox for Android 14 – 22 (Release date: 2012-06-26)
prefix
prefix Implemented with the vendor prefix: moz
Firefox for Android – Full support
Firefox for Android 23 (Release date: 2013-08-06)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – No support
Safari on iOS 6 – 6 (Release date: 2012-09-10)
prefix
prefix Implemented with the vendor prefix: webkit
Safari on iOS – Full support
Safari on iOS 7 (Release date: 2013-09-18)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1.5 (Release date: 2013-09-25)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – No support
WebView on iOS 6 – 6 (Release date: 2012-09-10)
prefix
prefix Implemented with the vendor prefix: webkit
WebView on iOS – Full support
WebView on iOS 7 (Release date: 2013-09-18)
footnote Full support
Deno – No support
Deno
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Requires a vendor prefix or different name for use.
Has more compatibility info.

See also