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 March 2020.
Die pause()
Methode des Web Animations API's Animation
Interface unterbricht die Wiedergabe der Animation.
Syntax
pause()
Parameter
Keine.
Rückgabewert
Keiner.
Ausnahmen
InvalidStateError
DOMException
-
Wird ausgelöst, wenn die
currentTime
der Animationunresolved
ist (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
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
pause |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
Siehe auch
- Web Animations API
Animation
fü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.