Home > Web Front-end > JS Tutorial > Solution to jQuery animation's continuous triggering, lagging and repeated execution_jquery

Solution to jQuery animation's continuous triggering, lagging and repeated execution_jquery

WBOY
Release: 2016-05-16 16:17:44
Original
1035 people have browsed it

The example in this article describes the solution to the continuous triggering and lagging execution of jQuery animation. Share it with everyone 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 external events, when the mouse triggers external element events quickly and continuously, the animation will be executed repeatedly with lag, which is indecent.

Solution:

1. Set the event on the triggering element to delayed processing to avoid the problem of delayed repeated execution (use setTimeout)

2. Stop all animations in advance when triggering an element's event, and then execute the corresponding animation event (use stop)

jquery stop:

Copy code The code is as follows:
//Grammar structure
$("#div").stop();//Stop the current animation and continue with the next animation
$("#div").stop(true);//Clear all animations of the element
$("#div").stop(false, true);//Let the current animation reach the end state directly and continue with the next animation
$("#div").stop(true, true);//Clear all animations of the element and let the current animation directly reach the end state

The second method is recommended here:
Copy code The code is as follows:
$("#div").stop().animate({width:" 100px"},100);

I hope this article will be helpful to everyone’s jQuery programming.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template