Dieser Inhalt wurde automatisch aus dem Englischen übersetzt, und kann Fehler enthalten. Erfahre mehr über dieses Experiment.

View in English Always switch to English

animation-play-state CSS property

Baseline Weitgehend verfügbar

Diese Funktion ist gut etabliert und funktioniert auf vielen Geräten und in vielen Browserversionen. Sie ist seit September 2015 browserübergreifend verfügbar.

Die animation-play-state CSS Eigenschaft legt fest, ob eine Animation läuft oder pausiert ist.

Wenn eine pausierte Animation fortgesetzt wird, beginnt die Animation dort, wo sie zum Zeitpunkt des Pausierens aufgehört hat, anstatt wieder von Anfang der Animationsfolge zu starten.

Probieren Sie es aus

animation-play-state: paused;
animation-play-state: running;
<section class="flex-column" id="default-example">
  <div class="animating" id="example-element"></div>
</section>
#example-element {
  background-color: #1766aa;
  color: white;
  margin: auto;
  margin-left: 0;
  border: 5px solid #333333;
  width: 150px;
  height: 150px;
  border-radius: 50%;
}

.animating {
  animation-name: slide;
  animation-duration: 3s;
  animation-timing-function: ease-in;
  animation-iteration-count: infinite;
  animation-direction: alternate;
}

@keyframes slide {
  from {
    background-color: orange;
    color: black;
    margin-left: 0;
  }
  to {
    background-color: orange;
    color: black;
    margin-left: 80%;
  }
}

Syntax

css
/* Single animation */
animation-play-state: running;
animation-play-state: paused;

/* Multiple animations */
animation-play-state: paused, running, running;

/* Global values */
animation-play-state: inherit;
animation-play-state: initial;
animation-play-state: revert;
animation-play-state: revert-layer;
animation-play-state: unset;

Werte

Diese Eigenschaft wird als kommaseparierte Liste der folgenden Schlüsselwortwerte angegeben:

running

Die Animation läuft derzeit ab.

paused

Die Animation ist derzeit pausiert.

Hinweis: Wenn Sie mehrere durch Kommas getrennte Werte für eine animation-* Eigenschaft angeben, werden sie in der Reihenfolge angewendet, in der die animation-names erscheinen. Für Situationen, in denen die Anzahl der Animationen und der animation-* Eigenschaftswerte nicht übereinstimmen, siehe Festlegen mehrerer Animations-Eigenschaftswerte.

Formale Definition

Anfangswertrunning
Anwendbar aufalle Elemente, ::before und ::after Pseudoelemente
VererbtNein
Berechneter Wertwie angegeben
AnimationstypNot animatable

Formale Syntax

animation-play-state = 
<single-animation-play-state>#

<single-animation-play-state> =
running |
paused

Beispiele

Pausieren einer Animation

Diese Animation ist pausiert, wird jedoch ausgeführt, wenn Sie mit der Maus darüber fahren.

HTML

html
<div class="box"></div>

CSS

css
.box {
  background-color: rebeccapurple;
  border-radius: 10px;
  width: 100px;
  height: 100px;
  animation-name: rotate;
  animation-duration: 0.7s;
  animation-iteration-count: infinite;
  animation-play-state: paused;
}

.box:hover {
  animation-play-state: running;
}

@keyframes rotate {
  0% {
    transform: rotate(0);
  }
  100% {
    transform: rotate(360deg);
  }
}

Ergebnis

Fahren Sie mit der Maus über das Rechteck, um die Animation abzuspielen.

Sehen Sie sich CSS-Animationen für Beispiele an.

Spezifikationen

Spezifikation
CSS Animations Level 1
# animation-play-state

Browser-Kompatibilität

Siehe auch