The animationName property is used for getting or setting the animation name for @keyframes’s reference.
Syntax
Following is the syntax for −
Setting the animationName property −
object.style.animationName = "none|keyframename|initial|inherit"
Values
Following are the values −
Sr.No | Values & Description |
---|---|
1 | None It is the default value mentioning there will be no animation. |
2 | keyframename To specify the keyframe name to bind the selector to. |
3 | initial For setting this property to initial value. |
4 | inherit To inherit the parent property value. |
Example
Let us look at the example for the animationName property −
<!DOCTYPE html> <html> <head> <style> div { width: 60px; height: 40px; border: 10px groove fuchsia; position: relative; animation-name: bravo; animation-iteration-count:infinite; animation-duration: 5s; } @keyframes bravo { from {left: 0px; } to {left: 600px;} } @keyframes NEW_FRAME { from {left:550px; } to {left: 0px;} } </style> <script> function nameChange(){ document.getElementById("DIV1").style.animationName="NEW_FRAME"; document.getElementById("Sample").innerHTML="The animation name is now NEW_FRAME"; } </script> </head> <body> <div id="DIV1">SAMPLE TEXT</div> <p>Click the below button to change the above animation fillmode property</p> <button onclick="nameChange()">CHANGE NAME</button> <p id="Sample"></p> </body> </html>
Output
This will produce the following output. The animation moves from left to right −
On clicking the CHANGE NAME button the animation moves from left to right −