The jQuery animation has a continuous trigger and lags behind for repeated execution.

Source: Internet
Author: User

The jQuery animation has a continuous trigger and lags behind for repeated execution.

This article describes how to solve the problem of continuous triggering and delayed execution of jQuery animation. Share it with you for your reference. The specific analysis is as follows:

When using slideUp, slideDown, animate, and other animations in jQuery, if the target element is driven by an external event, when the mouse quickly triggers an external element event continuously, the animation will be repeatedly executed in a delayed manner, its performance is not elegant.

Solution:

1. Set the event on the trigger element to delayed processing to avoid the problem of delayed execution (using setTimeout)

2. stop all animations in advance when an element event is triggered, and then execute the corresponding animation event (use stop)

Jquery stop:
Copy codeThe Code is as follows: // syntax structure
$ ("# Div"). stop (); // stop the current animation and continue the next Animation
$ ("# Div"). stop (true); // clear all animations of the element
$ ("# Div"). stop (false, true); // Let the current animation directly reach the final state and continue the next Animation
$ ("# Div"). stop (true, true); // clear all animations of the element so that the current animation reaches the final state.
The second method is recommended here:
Copy codeThe Code is as follows: $ ("# div"). stop (). animate ({width: "100px"}, 100 );

I hope this article will help you with jQuery programming.

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.