window.cancelAnimationFrame() - Web APIs 编辑
The window.cancelAnimationFrame()
method cancels an animation frame request previously scheduled through a call to window.requestAnimationFrame()
.
Syntax
window.cancelAnimationFrame(requestID);
Parameters
requestID
- The ID value returned by the call to
window.requestAnimationFrame()
that requested the callback.
Examples
var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
var cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame;
var start = window.mozAnimationStartTime; // Only supported in FF. Other browsers can use something like Date.now().
var myReq;
function step(timestamp) {
var progress = timestamp - start;
d.style.left = Math.min(progress / 10, 200) + 'px';
if (progress < 2000) {
// it's important to update the requestId each time you're calling requestAnimationFrame
myReq = requestAnimationFrame(step);
}
}
myReq = requestAnimationFrame(step);
// the cancelation uses the last requestId
cancelAnimationFrame(myReq);
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'cancelAnimationFrame()' in that specification. | Living Standard |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论