--- title: window.cancelAnimationFrame slug: Web/API/Window/cancelAnimationFrame translation_of: Web/API/Window/cancelAnimationFrame ---
{{APIRef}}{{SeeCompatTable}}

概述

取消一个先前通过调用{{ domxref("window.requestAnimationFrame()") }}方法添加到计划中的动画帧请求.

语法

window.mozCancelAnimationFrame(requestID);               // Firefox

参数

requestID
先前调用{{ domxref("window.requestAnimationFrame()") }}方法时返回的ID.

示例

var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
                            window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;

var cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame;

var start = window.mozAnimationStartTime;  // 只有Firefox支持mozAnimationStartTime属性,其他浏览器可以使用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);

window.cancelAnimationFrame(myReq);

浏览器兼容性

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support

21.0 {{ property_prefix("webkit") }}

24.0 脱前缀

{{ CompatGeckoDesktop("11.0") }} {{ property_prefix("moz") }} 

10 {{ CompatUnknown() }}

6.0 {{ property_prefix("webkit") }}

Feature Android Chrome for Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }}

{{ CompatUnknown() }}

{{ CompatGeckoMobile("11.0") }} {{ property_prefix("moz") }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}

规范

{{ spec("http://www.w3.org/TR/animation-timing/#cancelAnimationFrame", "Timing control for script-based animations: cancelAnimationFrame", "WD") }}

相关链接