Cette page a été traduite à partir de l'anglais par la communauté. Vous pouvez contribuer en rejoignant la communauté francophone sur MDN Web Docs.

View in English Always switch to English

animation-play-state

Baseline Widely available

Cette fonctionnalité est bien établie et fonctionne sur de nombreux appareils et versions de navigateurs. Elle est disponible sur tous les navigateurs depuis septembre 2015.

La propriété CSS animation-play-state définit si une animation est en cours ou en pause.

Reprendre une animation en pause fera démarrer l'animation là où elle s'est arrêtée au moment de la pause, plutôt que de recommencer depuis le début de la séquence d'animation.

Exemple interactif

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%;
  }
}

Syntaxe

css
/* Animation unique */
animation-play-state: running;
animation-play-state: paused;

/* Animations multiples */
animation-play-state: paused, running, running;

/* Valeurs globales */
animation-play-state: inherit;
animation-play-state: initial;
animation-play-state: revert;
animation-play-state: revert-layer;
animation-play-state: unset;

Valeurs

running

L'animation est actuellement en cours.

paused

L'animation est actuellement en pause.

Note : Lorsque vous indiquez plusieurs valeurs séparées par des virgules sur une propriété animation-*, elles sont appliquées aux animations dans l'ordre d'apparition des animation-name. Si le nombre d'animations et de valeurs de propriété animation-* ne correspond pas, voir Définir plusieurs valeurs de propriétés d'animation.

Définition formelle

Valeur initialerunning
Applicabilitétous les éléments, ainsi que les pseudo-elements ::before et ::after
Héritéenon
Valeur calculéecomme spécifié
Type d'animationNot animatable

Syntaxe formelle

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

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

Exemples

Mettre une animation en pause

Cette animation est en pause, mais s'exécute lorsque vous la survolez.

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);
  }
}

Résultat

Passez la souris sur le rectangle pour lancer l'animation.

Voir Animations CSS pour des exemples.

Spécifications

Specification
CSS Animations Level 1
# animation-play-state

Compatibilité des navigateurs

Voir aussi