JQuery Effects-Animations

Source: Internet
Author: User
Tags jquery library

The JQuery animate () method allows you to create custom animations.

Examples of jQuery animations

Jquery JQuery Animation-Animate () method

The JQuery animate () method is used to create custom animations.

Grammar:

$( 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.

The following example shows a simple application of the animate () method. It moves the <div> element to the right by 250 pixels:

Instance $ ("button"). Click (function () {
$ ("div"). Animate ({left: ' 250px '});
});
Try it»

By default, all HTML elements have a static location and cannot be moved.
To operate the location, remember to first set the element's CSS position property to relative, fixed, or absolute!

JQuery Animate ()-Manipulate multiple properties

Note that multiple properties can be used in the process of generating an animation:

Instance $ ("button"). Click (function () {
$ ("div"). Animate ({
Left: ' 250px ',
Opacity: ' 0.5 ',
Height: ' 150px ',
Width: ' 150px '
});
});
Try it»

Can I manipulate all CSS properties using the Animate () method?

Yes, almost possible! 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 ()-Using relative values

You can also define a relative value (this value relative to the current value of the element). You need to precede the value with + = or-=:

Instance $ ("button"). Click (function () {
$ ("div"). Animate ({
Left: ' 250px ',
Height: ' +=150px ',
Width: ' +=150px '
});
});
Try it»

JQuery animate ()-Use predefined values

You can even set the animation value of a property to "show", "Hide", or "toggle":

Instance $ ("button"). Click (function () {
$ ("div"). Animate ({
Height: ' Toggle '
});
});
Try it»

JQuery animate ()-Use the queue feature

By default, JQuery provides queue functionality for animations.

This means that if you write multiple animate () calls after each other, JQuery creates an "internal" queue that contains these method calls. These animate calls are then run individually.

Instance 1$ ("button"). Click (function () {
var div=$ ("div");
Div.animate ({height: ' 300px ', opacity: ' 0.4 '}, "slow");
Div.animate ({width: ' 300px ', opacity: ' 0.8 '}, "slow");
Div.animate ({height: ' 100px ', opacity: ' 0.4 '}, "slow");
Div.animate ({width: ' 100px ', opacity: ' 0.8 '}, "slow");
});
Try it»

The following example moves the <div> element to the right by 100 pixels, and then increases the font size of the text:

Instance 2$ ("button"). Click (function () {
var div=$ ("div");
Div.animate ({left: ' 100px '}, "slow");
Div.animate ({fontSize: ' 3em '}, "slow");
});
Try it»

JQuery Effects-Animations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.