docs.rodeo

MDN Web Docs mirror

Window: cancelAnimationFrame() method

{{APIRef}} 

The window.cancelAnimationFrame() method cancels an animation frame request previously scheduled through a call to {{domxref("window.requestAnimationFrame()")}} .

Syntax

cancelAnimationFrame(requestID)

Parameters

Return value

None ({{jsxref("undefined")}} ).

Examples

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

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN