Open In App

HTML | DOM Style animationDirection Property

The animationDirection property is used to set or return the animation direction. This property will have no effect if the animation is set to place only once. 

Syntax:



object.style.animationDirection;
object.style.animationDirection = "normal|reverse|alternate|
alternate-reverse|initial|inherit"

Property Value: The animationDirection property values are listed below:

Example 1:



Program: 




<!DOCTYPE html>
<html>
     
<head>
    <style>
        div {
            color:green;
            font-size:70px;
            font-weight:bold;
            position: relative;
             
             /* Chrome, Safari, Opera */
            -webkit-animation: animate 3s infinite;
            animation: animate 3s infinite;
        }
         
        /* Chrome, Safari, Opera */
        @-webkit-keyframes animate {
            from {top: 0px;}
            to {top: 200px;}
        }
         
        @keyframes animate {
            from {top: 0px;}
            to {top: 200px;}
        }
    </style>
</head>
 
<body>
     
    <button onclick = "myGeeks()">
        Click Here!
    </button>
     
    <div id = "GFG">
        GeeksforGeeks
    </div>
     
    <script>
    function myGeeks() {
         
        // Code for Chrome, Safari, and Opera
        document.getElementById("GFG").style.WebkitAnimationDirection
                = "normal";
                 
        document.getElementById("GFG").style.animationDirection
                = "normal";
    }
    </script>
</body>
 
</html>                              

Output:

 

Example 2:

Program: 




<!DOCTYPE html>
<html>
     
<head>
    <style>
        div {
            color:green;
            font-size:70px;
            font-weight:bold;
            position: relative;
             
             /* Chrome, Safari, Opera */
            -webkit-animation: animate 3s infinite;
            animation: animate 3s infinite;
        }
         
        /* Chrome, Safari, Opera */
        @-webkit-keyframes animate {
            from {top: 0px;}
            to {top: 200px;}
        }
         
        @keyframes animate {
            from {top: 0px;}
            to {top: 200px;}
        }
    </style>
</head>
 
<body>
     
    <button onclick = "myGeeks()">
        Click Here!
    </button>
     
    <div id = "GFG">
        GeeksforGeeks
    </div>
     
    <script>
    function myGeeks() {
         
        // Code for Chrome, Safari, and Opera
        document.getElementById("GFG").style.WebkitAnimationDirection
                = "reverse";
                 
        document.getElementById("GFG").style.animationDirection
                = "reverse";
    }
    </script>
</body>
 
</html>                          

Output:

 

Example 3:

Program: 




<!DOCTYPE html>
<html>
     
<head>
    <style>
        div {
            color:green;
            font-size:70px;
            font-weight:bold;
            position: relative;
             
             /* Chrome, Safari, Opera */
            -webkit-animation: animate 3s infinite;
            animation: animate 3s infinite;
        }
         
        /* Chrome, Safari, Opera */
        @-webkit-keyframes animate {
            from {top: 0px;}
            to {top: 200px;}
        }
         
        @keyframes animate {
            from {top: 0px;}
            to {top: 200px;}
        }
    </style>
</head>
 
<body>
     
    <button onclick = "myGeeks()">
        Click Here!
    </button>
     
    <div id = "GFG">
        GeeksforGeeks
    </div>
     
    <script>
    function myGeeks() {
         
        // Code for Chrome, Safari, and Opera
        document.getElementById("GFG").style.WebkitAnimationDirection
                = "alternate";
                 
        document.getElementById("GFG").style.animationDirection
                = "alternate";
    }
    </script>
</body>
 
</html>                               

Output:

 

Example 4:

Program: 




<!DOCTYPE html>
<html>
     
<head>
    <style>
        div {
            color:green;
            font-size:70px;
            font-weight:bold;
            position: relative;
             
             /* Chrome, Safari, Opera */
            -webkit-animation: animate 3s infinite;
            animation: animate 3s infinite;
        }
         
        /* Chrome, Safari, Opera */
        @-webkit-keyframes animate {
            from {top: 0px;}
            to {top: 200px;}
        }
         
        @keyframes animate {
            from {top: 0px;}
            to {top: 200px;}
        }
    </style>
</head>
 
<body>
     
    <button onclick = "myGeeks()">
        Click Here!
    </button>
     
    <div id = "GFG">
        GeeksforGeeks
    </div>
     
    <script>
    function myGeeks() {
         
        // Code for Chrome, Safari, and Opera
        document.getElementById("GFG").style.WebkitAnimationDirection
                = "alternate-reverse";
                 
        document.getElementById("GFG").style.animationDirection
                = "alternate-reverse";
    }
    </script>
</body>
 
</html>                             

Output:

 

Supported Browsers: The browser supported by DOM animationDirection property are listed below:


Article Tags :