Explain the use of .animate() function in jQuery
Introduction: The jQuery animate() function performs custom animations on a set of CSS properties.
- properties (*required): These define the objects of CSS properties and values to animate. Only numeric values such as height, width, left, etc can be animated whereas the properties that are non-numeric cannot be animated such as background color. In addition to numeric values each property can take the strings ‘show’, ‘hide’, and ‘toggle’.
- duration (optional): It gives the number or duration for how long the animation will run. This is given in milliseconds. The default value if not specified will be 400 milliseconds. The string ‘fast’ indicates the value of 200 milliseconds whereas the string ‘slow’ indicates the value of 600 milliseconds.
- easing(optional): It specifies the speed at which the animation progresses at different points within the animation. The default value is string ‘swing’. The ‘linear’ value will run the animation at a constant pace.
- complete(optional): A callback function that is called once the animation is complete.
Example 1: In this example, we are animating the circle by increasing the height and width of the circle. We are also using a callback function that alerts a message once the animation is completed.
Example 2: In this example, we are animating a logo image that jumps up and down without stopping.We repeatedly calling the function so that the animation doesn’t stop as shown in the code below.
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML course.