Animations in JavaScript
JavaScript Animations
We can create a simple animation. To create the best animation, we have to change the properties of an element at small intervals of time. This can be achieved by using the setInterval() method, which allows us to create a timer and call a function to change properties repeatedly at defined intervals (in milliseconds).
The setInterval() method:-
The setInterval() method is used for calling a function at specified intervals in milliseconds. It continues calling the method until clearInterval() is called or otherwise, the window is closed. For your information, 1000 milliseconds = 1 second.
Syntax:-
Its syntax is:- setInterval(function, milliseconds, param1, ...)
Return:-
Its return is:- id of timer in number which can be used with clearInterval(id) to cancel the timer
Function Explanation:-
Parameter | Description |
function | Required. The function to execute |
milliseconds | Required. The execution interval. |
param1, ... | Optional. Additional parameters to pass to the function. |