Attribut ANIMATION-PLAY-STATE
Rôle
L’attribut animation-play-state permet de spécifier si une animation est en pause ou en marche.
Cet attribut est souvent utilisé avec Javascript ou comme dans l’exemple ci-dessous avec une pseudo-class :hover.
Version : CSS3
Héritage (inherit) : non
Propriété Javascript : element.style.animationPlayState
Testez vous-même cet attribut
Utilisez Codepen.
– Le code CSS
body{
padding: 10px;
background-color: rgb(230,230,230);
}
img{
border-radius: 50%;
width: 200px;
position: relative;
display: block;
margin: 0 auto;
border: thin solid orange;
animation-name: cos;
animation-duration: 4s;
animation-timing-function:linear ;
animation-iteration-count: infinite;
}
img:hover{
animation-play-state: paused;
}
@keyframes cos {
0% {transform:rotate(0deg)}
100% {transform:rotate(360deg)}
}
– Le code HTML
<img src="//lorempixel.com/output/animals-q-c-200-200-10.jpg" alt="">
Résultat
Survolez l’image pour mettre l’animation en pause. Lorsque vous quittez le survol, l’animation reprend là ou elle s’est arrêtée
Compatibilité





L’attribut animation-play-state est pris en charge par tous les principaux navigateurs.
A partir d’Internet Explorer 10.
Pour implémenter cet attribut sur un ensemble de navigateur, vous devez utilisez les préfixes -webkit-(Chrome, Safari, Android…), -moz- (Mozilla), -o- (Opéra).
Valeurs
Les différentes valeurs de l’attribut animation-play-state sont:
- running
- Animation est en marche : valeur par défaut
Syntaxe :
animation-play-state : running - paused
- Animation est en pause
Syntaxe :
animation-play-state : paused - initial
- Défini à sa valeur initiale (attention pas pris en charge par Internet Explorer et Opéra en dessous de la version 15). Peut être utilisé pour « neutraliser » une spécification.
Syntaxe :
animation-play-state : initial - inherit
- Hérite de la même propriété que l’élément parent.
Syntaxe :
animation-play-state : inherit
A voir aussi
animation– animation-delay– animation-duration– animation-timing-function





