Dans ce chapitre nous allons voir comment fonctionne la propriété css animation-fill-mode et comment l'utiliser avec des exemples.
La propriété animation-fill-mode spécifie un style pour l'élément lorsque l'animation n'est pas jouée (avant qu'elle ne commence, après qu'elle se termine, ou les deux)..
animation-fill-mode: none|forwards|backwards|both|initial|inherit;
Valeurs par défaut | none |
---|---|
Inherited: | non |
Animable : | non En savoir plus sur l'animable |
Version: | CSS3 |
Syntaxe JavaScript: | object.style.animationFillMode="forwards" |
Explorateur | ![]() | ![]() | ![]() | ![]() | ![]() | |
---|---|---|---|---|---|---|
Verssion | 43 4 -webkit- | 10 | 16 5 -moz- | 9 4 -webkit- | 30 15 -webkit- 12 -o- |
Exemple Copier le code
<!DOCTYPE html> <html lang="fr"> <head> <meta charset="UTF-8"> <title> CSS | La propriété animation-duration </title> <style> div { width: 100px; height: 100px; border: solid 1px; position: relative; animation: monAnimation 3s; animation-delay:2s; animation-fill-mode: forwards; } @keyframes monAnimation { from {top: 0px;background-color:red;} to {top: 200px; background-color: blue;} } </style> </head> <body> <h1>animation-fill-mode: forwards</h1> <p>Lorsque l'animation se termine, l'élément div conserve les valeurs de style de la dernière image clé :</p> <div></div> </body> </html>
Exemple Copier le code
<!DOCTYPE html> <html lang="fr"> <head> <meta charset="UTF-8"> <title> CSS | La propriété animation-duration </title> <style> div { width: 100px; height: 100px; border: solid 1px; position: relative; animation: monAnimation 3s; animation-fill-mode: backwards; } @keyframes monAnimation { from {left: 0px;background-color:red;} to {left: 300px; background-color: blue;} } </style> </head> <body> <h1>animation-fill-mode: forwards</h1> <pre>Si on clique sur le bouton "MODIFIER" lorsque l'animation se termine, l'élément div conserve les valeurs de style de la dernière image clé :</pre> <button onclick="maFonction()"> MODIFIER </button> <div id="monDIV"></div> <script> function maFonction() { document.getElementById("monDIV").style.animationFillMode = "forwards"; } </script> </body> </html>
Livre numérique court pour comprendre la méthode secrète permettant d'obtenir des likes sans fin sur Facebook.
GAGNER DE L'ARGENT