Getting Started with jquery (8) animation effects

Source: Internet
Author: User

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");     
});

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.