Window: cancelAnimationFrame() Methode
Baseline
Weitgehend verfügbar
Diese Funktion ist gut etabliert und funktioniert auf vielen Geräten und in vielen Browserversionen. Sie ist seit Juli 2015 browserübergreifend verfügbar.
Die window.cancelAnimationFrame() Methode storniert eine Animations-Frame-Anfrage, die zuvor durch einen Aufruf von window.requestAnimationFrame() geplant wurde.
Syntax
js
cancelAnimationFrame(requestID)
Parameter
requestID-
Der ID-Wert, der durch den Aufruf von
window.requestAnimationFrame()zurückgegeben wurde und die Callback-Anforderung angefordert hat.
Rückgabewert
Keiner (undefined).
Beispiele
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);
Spezifikationen
| Spezifikation |
|---|
| HTML> # animationframeprovider-cancelanimationframe> |