Animation: pause() Methode
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since März 2020.
Die pause() Methode des Web Animations API's Animation Interface unterbricht die Wiedergabe der Animation.
Syntax
pause()
Parameter
Keine.
Rückgabewert
Keiner.
Ausnahmen
InvalidStateErrorDOMException-
Wird ausgelöst, wenn die
currentTimeder Animationunresolvedist (vielleicht wurde sie noch nicht gestartet) und die Endzeit der Animation positive Unendlichkeit ist.
Beispiel
Animation.pause() wird häufig im Alice in Web Animations API Land Growing/Shrinking Alice Game verwendet, hauptsächlich weil Animationen, die mit der Element.animate() Methode erstellt wurden, sofort mit der Wiedergabe beginnen und manuell angehalten werden müssen, wenn Sie das vermeiden möchten:
// animation of the cupcake slowly getting eaten up
const nommingCake = document
.getElementById("eat-me_sprite")
.animate(
[{ transform: "translateY(0)" }, { transform: "translateY(-80%)" }],
{
fill: "forwards",
easing: "steps(4, end)",
duration: aliceChange.effect.timing.duration / 2,
},
);
// doesn't actually need to be eaten until a click event, so pause it initially:
nommingCake.pause();
Zusätzlich beim Zurücksetzen:
// An all-purpose function to pause the animations on Alice, the cupcake, and the bottle that reads "drink me."
const stopPlayingAlice = () => {
aliceChange.pause();
nommingCake.pause();
drinking.pause();
};
// When the user releases the cupcake or the bottle, pause the animations.
cake.addEventListener("mouseup", stopPlayingAlice, false);
bottle.addEventListener("mouseup", stopPlayingAlice, false);
Spezifikationen
| Specification |
|---|
| Web Animations> # dom-animation-pause> |
Browser-Kompatibilität
Loading…
Siehe auch
- Web Animations API
Animationfür weitere Methoden und Eigenschaften, die Sie zur Steuerung von Animationen auf Webseiten verwenden können.Animation.reverse()um eine Animation rückwärts abzuspielen.Animation.finish()um eine Animation zu beenden.Animation.cancel()um eine Animation abzubrechen.