Window: cancelAnimationFrame() 方法
window.cancelAnimationFrame() 方法会取消通过调用 window.requestAnimationFrame() 方法之前安排好的动画帧请求。
语法
js
cancelAnimationFrame(requestID)
参数
- requestID
- 
调用 window.requestAnimationFrame()请求回调时返回的 ID 值。
返回值
无(undefined)。
示例
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);
规范
| 规范 | 
|---|
| HTML # animationframeprovider-cancelanimationframe | 
浏览器兼容性
加载中…