The JQuery animate () method allows you to create custom animations.
Grammar:
1 $ (selector). Animate ({params},speed,callback);
The required params parameter defines the CSS property that forms the animation.
The optional speed parameter specifies the length of the effect. It can take the following values: "Slow", "fast", or milliseconds.
The optional callback parameter is the name of the function that is executed after the animation is completed.
Example:
1 $ ("button"). Click (function () {
2 $ ("div"). Animate ({left: ' 250px '});
3 });
By default, the location of all HTML elements is static and cannot be moved. To manipulate the location, remember to first set the element's CSS position property to relative, fixed, or absolute.
Example:
1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <Scriptsrc= "Jquery-2.2.0.min.js">5 </Script>6 <Script> 7 $ (document). Ready (function(){8 $("Button"). Click (function(){9 $("Div"). Animate ({left:'250px'});Ten }); One }); A </Script> - </Head> - the <Body> - <Button>Start animation</Button> - <Divstyle= "background: #98bf21; height:100px;width:100px;position:absolute;"> + </Div> + </Body> A </HTML>
JQuery Animate ()-Multiple properties can be used simultaneously during animation generation:
1 $ ("button"). Click (function () {2 $ ("div"). Animate ({3left : ' 250px ',4 opacity: ' 0.5 ',5 height: ' 150px ',6 width: ' 150px ' 7 }); 8
Tip: You can almost manipulate all CSS properties using the Animate () method. However, one important thing to remember: when using animate (), you must use the Camel notation to write all property names, for example, you must use Paddingleft instead of Padding-left, using marginright instead of Margin-right, wait.
At the same time, color animations are not included in the core JQuery library.
If you need to generate color animations, you need to download the color animations plugin from jquery.com.
JQuery animate ()-you can define a relative value (the value that corresponds to the current value of the element). You need to precede the value with + = or-=:
1 $ ("button"). Click (function () {2 $ ("div"). Animate ({3left : ' 250px ',4 height: ' +=150px ',5 width: ' +=150px '6 }); 7 });
The effect of the execution is that the blocks grow.
You can set the animation value of a property to "show", "Hide", or "toggle":
1 $ ("button"). Click (function () {
2 $ ("div"). Animate ({
3 height: ' Toggle '
4 });
5 });
Using the queue feature
If you want to perform different animations after each other, use the queue feature:
1 $ ("button"). Click (function () {2 var div=$ ("div"); 3 div.animate ({height: ' 300px ', opacity: ' 0.4 '}, "slow"); 4 div.animate ({width: ' 300px ', opacity: ' 0.8 '}, "slow"); 5 div.animate ({height: ' 100px ', opacity: ' 0.4 '}, "slow"); 6 div.animate ({width: ' 100px ', opacity: ' 0.8 '}, "slow"); 7 });
1 $ ("button"). Click (function () {2 var div=$ ("div"); 3 div.animate ({left: ' 100px '}, "slow"); 4 div.animate ({fontSize: ' 3em '}, "slow"); 5 });
JQuery Effects-Animations