--- title: window.cancelAnimationFrame slug: Web/API/Window/cancelAnimationFrame translation_of: Web/API/Window/cancelAnimationFrame ---
取消一个先前通过调用{{ domxref("window.requestAnimationFrame()") }}方法添加到计划中的动画帧请求.
window.mozCancelAnimationFrame(requestID); // Firefox
requestID
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") }}