JS in the hover event when the bug and solution

Source: Internet
Author: User

The hover event is a common problem we encountered in the early stages of development, but there is no discovery that there will be a bug, for example, you move to an element, let it execute a method, and then you quickly move out of the time, he will be bright blind your eyes strobe effect, And it's going to be like Alzheimer's. Delayed display, 24K titanium alloy will also be blind, the mouse repeatedly in the corresponding area of the slide, the animation will continue to execute, until and the number of times the mouse passed the same position. For example, the mouse moves 3 times, moves out 3 times, the animation will appear three times. This obviously has a profound impact on the user experience. Then our company large back-end told me that the MouseEvent and Monseleave merged into a hover event, but also the meaning of the words to tell me that this is the problem (the big front end unexpectedly by the back end of the education, excessive), but I do not have any eggs after the merger (PA Face), I remember this is the hover of the different wording. OK, no chatter, start talking about your solution:

At first I thought of event bubbling or event capture, because I use the DOM structure is Li inside the package UL, so think of event capture, then to stop the event capture it,

E.stoppropagation ()
Still flashing, and not resolved. So that's not the reason, so stop it from the source.



Method One: Delay error operation plug-in-hoverintent

: http://www.jq22.com/jquery-info274
This plugin can be a good solution to this bug, prevent misoperation, compatible with various browsers, including disgusting IE6, conscience recommended


Method Two: The Stop method of JQ

Put a stop () in front of your animation, I need to write Slideup (), so I should write
$ ("Dom"). Stop (False,false). Fadeup ()

Perfect solution!!!



JS in the hover event when the bug and solution

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.