Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

window.cancelAnimationFrame

这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀.由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变.

概述

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

语法

window.mozCancelAnimationFrame(requestID);               // Firefox

参数

requestID
先前调用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);

浏览器兼容性

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

21.0 webkit

24.0 脱前缀

11.0 (11.0) moz 

10 ?

6.0 webkit

Feature Android Chrome for Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support ?

?

11.0 (11.0) moz ? ? ?

规范

Timing control for script-based animations: cancelAnimationFrameWD

相关链接

文档标签和贡献者

 此页面的贡献者: teoli, insideyiqi, ziyunfei
 最后编辑者: teoli,