Open In App

HTML | DOM Style animationTimingFunction Property

The Style animationTimingFunction property in HTML DOM defines the time of transition between the styles to make transitions smooth. It specifies the speed curve of an animation. 
Syntax: 

animation-timing-function: cubic-bezier(n1, n2, n3, n4)|linear
|ease|ease-in|ease-out|initial|inherit;

Return Values: It returns a String that represents the animation-timing-function property of an element
Property Values: 



Example: cubic-bezier(n1, n2, n3, n4) 




<!DOCTYPE html>
<html>
     
<head>
    <style>
        div {
            font-size: 50px;
            color: darkgreen;
            position: relative;
            height: 150px;
            width: 150px;
            animation: movement 5s infinite;
            -webkit-animation: movement 5s infinite;
        }
         
        @-webkit-keyframes movement {
            from {left: 50px;}
            to {left: 500px;}
        }
         
        @keyframes movement {
            from {left: 50px;}
            to {left: 500px;}
        }
    </style>
</head>
 
<body>
    <div id = "geeks">
        GfG
    </div>
     
    <button onclick = "myText()">
        Click to change speed
    </button>
     
    <script>
    function myText() {
    document.getElementById("geeks").style.WebkitAnimationTimingFunction
            = "cubic-bezier(0.7,0.1,0.3,0.2)";
     
    document.getElementById("geeks").style.animationTimingFunction
            = "cubic-bezier(0.7,0.1,0.3,0.2)";
    }
    </script>
</body>
 
</html>                   

Output: 
 



Example: linear 
 




<!DOCTYPE html>
<html>
     
<head>
    <style>
        div {
            font-size: 50px;
            color: darkgreen;
            position: relative;
            height: 150px;
            width: 150px;
            animation: movement 5s infinite;
            -webkit-animation: movement 5s infinite;
        }
         
        @-webkit-keyframes movement {
            from {left: 50px;}
            to {left: 500px;}
        }
         
        @keyframes movement {
            from {left: 50px;}
            to {left: 500px;}
        }
    </style>
</head>
 
<body>
    <div id = "geeks">
        GfG
    </div>
     
    <button onclick="myText()">
        Click to change speed
    </button>
     
    <script>
    function myText() {
    document.getElementById("geeks").style.WebkitAnimationTimingFunction
            = "linear";
     
    document.getElementById("geeks").style.animationTimingFunction
            = "linear";
    }
    </script>
</body>
 
</html>                   

Output: 
 

Example: ease 
 




<!DOCTYPE html>
<html>
     
<head>
    <style>
        div {
            font-size: 50px;
            color: darkgreen;
            position: relative;
            height: 150px;
            width: 150px;
            animation: movement 5s infinite;
            -webkit-animation: movement 5s infinite;
        }
         
        @-webkit-keyframes movement {
            from {left: 50px;}
            to {left: 500px;}
        }
         
        @keyframes movement {
            from {left: 50px;}
            to {left: 500px;}
        }
    </style>
</head>
 
<body>
    <div id = "geeks">
        GfG
    </div>
     
    <button onclick = "myText()">
        Click to change speed
    </button>
     
    <script>
    function myText() {
    document.getElementById("geeks").style.WebkitAnimationTimingFunction
            = "ease";
     
    document.getElementById("geeks").style.
            = "ease";
    }
    </script>
</body>
 
</html>                   

Output: 
 

Example: ease-in 
 




<!DOCTYPE html>
<html>
     
<head>
    <style>
        div {
            font-size: 50px;
            color: darkgreen;
            position: relative;
            height: 150px;
            width: 150px;
            animation: movement 5s infinite;
            -webkit-animation: movement 5s infinite;
        }
         
        @-webkit-keyframes movement {
            from {left: 50px;}
            to {left: 500px;}
        }
         
        @keyframes movement {
            from {left: 50px;}
            to {left: 500px;}
        }
    </style>
</head>
 
<body>
    <div id = "geeks">
        GfG
    </div>
     
    <button onclick = "myText()">
        Click to change speed
    </button>
     
    <script>
    function myText() {
    document.getElementById("geeks").style.WebkitAnimationTimingFunction
            = "ease-in";
     
    document.getElementById("geeks").style.animationTimingFunction
            = "ease-in";
    }
    </script>
</body>
 
</html>                   

Output: 
 

Example: ease-out 
 




<!DOCTYPE html>
<html>
     
<head>
    <style>
        div {
            font-size: 50px;
            color: darkgreen;
            position: relative;
            height: 150px;
            width: 150px;
            animation: movement 5s infinite;
            -webkit-animation: movement 5s infinite;
        }
         
        @-webkit-keyframes movement {
            from {left: 50px;}
            to {left: 500px;}
        }
         
        @keyframes movement {
            from {left: 50px;}
            to {left: 500px;}
        }
    </style>
</head>
 
<body>
    <div id = "geeks">
        GfG
    </div>
     
    <button onclick = "myText()">
        Click to change speed
    </button>
     
    <script>
    function myText() {
    document.getElementById("geeks").style.WebkitAnimationTimingFunction
            = "ease-out";
     
    document.getElementById("geeks").style.animationTimingFunction
            = "ease-out";
    }
    </script>
</body>
 
</html>                   

Output: 
 

Example: ease-in-out 
 




<!DOCTYPE html>
<html>
     
<head>
    <style>
        div {
            font-size: 50px;
            color: darkgreen;
            position: relative;
            height: 150px;
            width: 150px;
            animation: movement 5s infinite;
            -webkit-animation: movement 5s infinite;
        }
         
        @-webkit-keyframes movement {
            from {left: 50px;}
            to {left: 500px;}
        }
         
        @keyframes movement {
            from {left: 50px;}
            to {left: 500px;}
        }
    </style>
</head>
 
<body>
    <div id = "geeks">
        GfG
    </div>
     
    <button onclick = "myText()">
        Click to change speed
    </button>
     
    <script>
    function myText() {
    document.getElementById("geeks").style.WebkitAnimationTimingFunction
            = "ease-in-out";
     
    document.getElementById("geeks").style.animationTimingFunction
            = "ease-in-out";
    }
    </script>
</body>
 
</html>                   

Output: 
 

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


Article Tags :