[Jquery tutorial] jquery callback function

Source: Internet
Author: User
Jquery animation Problems

Many jquery functions involve animation. These functions maySpeedOrDurationAs an optional parameter.

Example:$ ("P"). Hide ("slow ")

SpeedOrDurationParameters can be set to many different values, such as "slow", "fast", "normal", or millisecond.

Instance

$ ("Button"). Click (function (){
$ ("P"). Hide (1000 );
});

Because JavaScript statements (commands) are executed one by one in order, the animated statements may produce errors or page conflicts because the animation is not completed yet.

To avoid this problem, you can add the callback function as a parameter.

 

Jquery callback function

Call the callback function when animation 100% is complete.

Typical Syntax:

$ (Selector). Hide (speed, callback)

CallbackA parameter is a function that is executed after the hide operation is complete.

Error (no callback)

$ ("P"). Hide (1000 );
Alert ("the paragraph is now hidden ");

Correct (with callback)
$ ("P"). Hide (1000, function () {alert ("the paragraph is now hidden ");});

Conclusion:If you want to execute a statement after an animation function, use the callback function.

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.