The previous Hide/show,slide In/out is also animated, and this article describes using animate () to implement a custom animation effect.
The basic syntax is as follows:
$ (selector). Animate ({params},speed,callback);
The required parameter is params, which defines the properties that the CSS uses for animation effects.
Optional parameter speed gives the time to fade in, you can use "slow", "fast", or a value (microseconds)
The Second optional parameter is the callback function, which is invoked after the animate () method finishes.
As in the following example, moving a <center> tag to its Left property equals 250px.
$ ("button"). Click (function () {
$ (' center '). Animate ({left: ' 250px '});
});
Note that by default, the position of all HTML elements is fixed and cannot be moved, so if you need to modify the position of the HTML elements, you need to set their CSS properties to relative, fixed, or absolute in advance.
Using animate to modify multiple properties
In the following example, you can use animate to modify multiple properties at the same time:
$ ("button"). Click (function () {
$ ("center"). Animate ({left
: ' 250px ',
opacity: ' 0.5 ',
height: ') 150px ',
width: ' 150px '
});
Note: The basic CSS properties can be used in animation, color modification is not in the jquery core library and needs to be done with the color animiation plugin.
Use attribute relative values
For CSS Properties, in addition to the absolute size used above, you can also use relative values to define, using "+" "-".
$ ("button"). Click (function () {
$ ("center"). Animate ({left
: ' 250px ',
height: ' +=150px ',
width: ' = 150px '
});
Use predefined values
You can also assign a value to a property by using a predefined value. such as "show", "Hide", or "toggle":
$ ("button"). Click (function () {
$ (' center '). Animate ({
height: ' Toggle '
});
});
Using the queue feature
The default jquery support is to string together multiple animation functions from one queue, and then one execution queue of instructions.
Like what:
$ ("button"). Click (function () {
var center=$ ("center");
Center.animate ({height: ' 300px ', opacity: ' 0.4 '}, "slow");
Center.animate ({width: ' 300px ', opacity: ' 0.8 '}, "slow");
Center.animate ({height: ' 100px ', opacity: ' 0.4 '}, "slow");
Center.animate ({width: ' 100px ', opacity: ' 0.8 '}, ' slow ');
});
Or
$ ("button"). Click (function () {
var center=$ ("center");
Center.animate ({left: ' 100px '}, "slow");
Center.animate ({fontsize: ' 3em '}, "slow");
});