Javascript examples for jQuery Method and Property:animate
The animate() method performs animation on CSS properties.
$(selector).animate({styles},speed,easing,callback);
Parameter | Require | Description |
---|---|---|
styles | Required. | one or more CSS properties/values to animate. |
speed | Optional. | speed of the animation. |
easing | Optional. | speed of the element in different points of the animation. |
callback | Optional. | function to call after the animation completes. |
speed Default value is 400 milliseconds
Possible speed values:
easing default value is "swing".
easing Possible values:
$(selector).animate({styles},{options});
Parameter | Require | Description |
---|---|---|
styles | Required. | one or more CSS properties/values to animate |
options | Optional. | additional options for the animation. |
Possible values:
The property names must be camel-cased when used with the animate() method.
You will need to write paddingLeft instead of padding-left, marginRight instead of margin-right, and so on.
Properties that can be animated:
The following code shows how to animate an element by changing its height.
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ var div = $("div"); startAnimation();/* w ww. j a v a2s .co m*/ function startAnimation(){ div.animate({height: 300}, "slow"); div.animate({width: 300}, "slow"); div.css("background-color", "blue"); div.animate({height: 100}, "slow"); div.animate({width: 100}, "slow", startAnimation); } }); }); </script> </head> <body> <button>Start Animation</button> <div style="width:50px;height:50px;position:absolute;left:10px;top:50px;background-color:red;"></div> </body> </html>