HTML DOM Style animationTimingFunction Property


The animationTimingFunction is used to specify the way animation progresses during its cycle. It does so by setting or returning the speed curve for an animation. The speed curve defines how smooth the transitions will be by specifying the time it takes animation to move from one state to another.

Syntax

Following is the syntax for −

Setting the animationTimingFunction property −

object.style.animationTimingFunction = "linear|ease|ease-in|ease-out|cubic-bezier(n, n, n, n)|initial|inherit"

Values

Following are the values −

Sr.NoValues & Description
1linear
This specifies that the animation has the same speed throughout the course of an animation.
2ease
This is the default value specifying the animation has a slow start and end but is faster in the middle.
3ease-in
The animation has a slow start.
4ease-out
The animation has a slow end.
5ease-in-out
The animation is slow at the start and also slow at the end.
6cubic-bezier(n, n, n,n)
Fo defining the cubic-bezier function for your custom values.
7initial
For setting this property to initial value.
8inherit
To inherit the parent property value.

Example

Let us look at the example for the animationTimingFunction property −

Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
   #PARA1{
      border: 2px solid black;
      position: relative;
      animation: demo 5s infinite;
      animation-timing-function: linear;
   }
   @keyframes demo {
      from {background-color: lightcoral; color:black;}
      to {background-color: indigo; color:white;}
   }
</style>
<script>
   function timingChange(){
      document.getElementById("PARA1").style.animationTimingFunction="ease";
      document.getElementById("Sample").innerHTML="The animation timing is now set to ease.";
   }
</script>
</head>
<body>
<p id="PARA1">
Lacus vel facilisis volutpat est velit. Id interdum velit laoreet id donec ultrices.
Praesent semper feugiat nibh sed pulvinar proin gravida hendrerit. Viverra nibh cras
pulvinar mattis nunc sed blandit libero.</p>
<p>Click the below button to change the above animation name</p>
<button onclick="timingChange()">CHANGE TIMING</button>
<p id="Sample"></p>
</body>
</html>

Output

This will produce the following output −

On clicking the CHANGE TIMING button −

Updated on: 15-Feb-2021

20 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements