Window: cancelAnimationFrame() 方法
window.cancelAnimationFrame() 方法會取消透過呼叫 window.requestAnimationFrame() 方法之前安排好的動畫幀請求。
語法
js
cancelAnimationFrame(requestID)
引數
requestID-
呼叫
window.requestAnimationFrame()請求回撥時返回的 ID 值。
返回值
無(undefined)。
示例
js
const start = document.timeline.currentTime;
let myReq;
function step(timestamp) {
const 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 cancellation uses the last requestId
cancelAnimationFrame(myReq);
規範
| 規範 |
|---|
| HTML # animationframeprovider-cancelanimationframe |
瀏覽器相容性
載入中…