About jquery animation lag problem (GO)

Source: Internet
Author: User

When the Slideup, Slidedown, animate and other animations are used in jquery, if the target element is driven by an external event, when the mouse triggers the external element event quickly, the animation will lag behind repeatedly, its performance is not elegant. Greatly affect the experience of using.

The problem was also encountered in development. No record of the habit, resulting in a long time to forget the common bug solution. Now found must be recorded.

Bug

Original code:

    $ (function() {            $ (". Box"). Hover (                function() {                    $ ("ul"). Slidedown;                },                function() {                    $ ("ul"). Slideup ();                }            );        });    

Solution Ideas:

Stops all animations in advance of the event that triggered the element, and then executes the corresponding animation event (using the Stop function).

Post-resolution code:

        $ (function() {            $ (". Box"). Hover (                function() {                    $ ("ul "). Stop (). Slidedown ()                ,                function() {                    $ (" UL "). Stop (). Slideup ();})        ;

With jquery's chained invocation, all animation effects are cleared before the element is animated.

After resolution:

The animation is performed only once, no matter how many times it is triggered.

About jquery animation lag problem (GO)

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.