Changing the animationName property of a <div> element:
document.getElementById("myDIV").style.animationName = "myNEWmove";
Click the button to change what keyframe to use in the animation:
<!DOCTYPE html> <html> <head> <style> div {// w ww . j a va 2 s .c o m width: 100px; height: 100px; background: red; position: relative; animation: mymove 2s infinite; } @keyframes mymove { from {left: 0px;} to {left: 200px;} } @keyframes myNEWmove { from {width: 0px;} to {width: 500px; background: blue;} } </style> </head> <body> <button onclick="myFunction()">Test</button> <script> function myFunction() { document.getElementById("myDIV").style.animationName = "myNEWmove"; } </script> <div id="myDIV"></div> </body> </html>
The animationName property sets or gets a name for the @keyframes
animation.
Property Values
Value | Description |
---|---|
none | Default . no animation |
keyframe-name | Sets the name of the keyframe |
initial | Sets this property to its default value. |
inherit | Inherits this property from its parent element. |
The animationName property returns a String representing the animation-name property of an element.