--- title: window.cancelAnimationFrame slug: Web/API/Window/cancelAnimationFrame translation_of: Web/API/Window/cancelAnimationFrame --- <div>{{APIRef}}{{SeeCompatTable}}</div> <h2 id="概述">概述</h2> <p>取消一个先前通过调用{{ domxref("window.requestAnimationFrame()") }}方法添加到计划中的动画帧请求.</p> <h2 id="语法">语法</h2> <pre class="eval">window.mozCancelAnimationFrame(<em>requestID</em>); // Firefox </pre> <h2 id="参数">参数</h2> <dl> <dt><code>requestID</code></dt> <dd>先前调用{{ domxref("window.requestAnimationFrame()") }}方法时返回的ID.</dd> </dl> <h2 id="Notes" name="Notes">示例</h2> <pre class="deki-transform">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); </pre> <h2 id="Browser_Compatibility" name="Browser_Compatibility">浏览器兼容性</h2> {{Compat("api.Window.cancelAnimationFrame")}} <h2 id="Specification" name="Specification">规范</h2> <p>{{ spec("http://www.w3.org/TR/animation-timing/#cancelAnimationFrame", "Timing control for script-based animations: cancelAnimationFrame", "WD") }}</p> <h2 id="相关链接">相关链接</h2> <ul> <li>{{ domxref("window.mozAnimationStartTime") }}</li> <li>{{ domxref("window.requestAnimationFrame()") }}</li> </ul>