jQuery Animation Effect

If you want to use the jQuery Animation Effect, jQuery comes with animation() methods to use. You can create easy animation effects using this method.

jQuery Animation Effect Using animate()

You can animate the HTML element with CSS properties that contain only the numeric values like width, height, padding, margin, etc. However, you cannot perform the jQuery animation effect using CSS properties containing non-numeric values like color, background, etc. The string values show, hide and toggle can only work with the animate method.

The syntax of animate() method is given below.
Syntax of animate()

The syntax of animate() method contains four parameters selectors, cssparameter, speed, and callback. The selector and cssparamter are the required fields and the last two parameters speed and callback can be used optionally.

Sr. No Parameter Name Description
1 selector If you want to access HTML element and apply jQuery animation effect, you need to use this parameter. It is the required parameter.
2 cssparameter The parameter ‘cssparameter’ contains the single or multiple CSS properties in commas with its values. For single value, use any CSS property like width:200px and for multiple CSS properties in comma separation like width:200px, height:50px, padding:20px etc. This is the required parameter.
3 speed The speed controls the speed of animation performs with the HTML element. There are three possible values for speed ‘slow’, ‘fast’ and value in milliseconds. It is the optional parameter.
4 callback The callback is the function you can specify to execute after the occurrence of the jQuery animation effect.

Example of animate()

Test it Live

Output


jQuery Animation Effect to Animate With Multiple CSS Properties

If you want to perform the animation with more than one CSS properties, you can do so by using comma separated properties with its values.

Below is the simple example you can check and use in your project.

Test it Live

Output


jQuery animate with Multiple Properties Using Queued Animation

If you want to perform the animation with multiple CSS properties performing animation one by one in the queue process, you can do so by using animate() many times with single CSS properties with each animate().

Below is the simple example you can check and use in your project.

Test it Live

Output


jQuery Animation Effect to Animate With Relative CSS Property values

If you want to perform the animation with the relative values of the CSS properties, you can do so by using the += or -= operators before the values of the CSS properties.

Check the below given examples to see how to use relative values for animation.

Output


You must also read.