Anime.js is a JavaScript animation library that simplifies creating animations. The anime()
function takes an object parameter composed of several
Note: If you are unfamiliar with Anime.js, click here to learn the basics.
The duration
, delay
, and endDelay
parameters are three of these key-value pairs we can use to control the timing of the animation. These three parameters fall under
Note: Check out other property parameters at this link.
duration
parameterThis parameter defines the total time that the animation takes in milliseconds.
We consider two boxes made using the <div>
tag for this example and the following. Moreover, we animate each box separately by using the anime()
function, and we set it to move vertically downwards.
duration
property of the first box's animation to 5000
milliseconds (5 seconds).duration
property of the second box's animation to 15000
milliseconds (15 seconds).As we can see, the second box with a larger duration takes more time to complete its animation.
delay
parameterThis parameter specifies the time to wait before starting the animation. The value is given in milliseconds.
We continue the same example but set each animation's duration to be the same.
delay
parameter and set it to 2000
milliseconds for the first animation.delay
to 4000
milliseconds.The boxes complete their animation in the same amount of time. However, the second box starts its animation later due to its higher delay
value.
endDelay
parameterContrary to delay
, the endDelay
parameter defines the time to wait after the animation ends.
In continuing the same example, we set the duration and delay of both animations to be the same.
endDelay
property to the first box's animation and set it to 100
milliseconds.direction
parameter. This parameter causes the animation to play normally first and then play in reverse.endDelay
property to the second box's animation and set it to 1000
milliseconds.In the above example, both boxes start moving simultaneously since their delay is the same. However, the second box has a longer endDelay
. Therefore, it waits longer after the animation ends to move back.
Free Resources