HTML DOM Style animationName Property


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.NoValues & Description
1None
It is the default value mentioning there will be no animation.
2keyframename
To specify the keyframe name to bind the selector to.
3initial
For setting this property to initial value.
4inherit
To inherit the parent property value.

Example

Let us look at the example for the animationName property −

Live Demo

<!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 −

Updated on: 15-Feb-2021

38 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements