--- 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);
{{ spec("http://www.w3.org/TR/animation-timing/#cancelAnimationFrame", "Timing control for script-based animations: cancelAnimationFrame", "WD") }}