The flicker problem of jquery caused by mouseover,mouseout bubbling

Source: Internet
Author: User

Because of the browser's bubbling behavior. Cause if mouseover,mouseout is defined on a DIV element at the same time, when the mouse moves to the child element in the Div, two operations mouseover and Mouseout are performed simultaneously.

Solution: block the bubbling behavior and do not trigger the mouseout operation when the mouseover is executed.

Method 1:
Deferred execution (setTimeout), cancellation delay (cleartimeout), is deferred execution when Mouseout, and cancellation of deferred execution at MouseOver. Mouseout is not triggered when the mouse moves over the div because of deferred execution.

$ (' div '). Mouseout (function () {     cleartimeout (t);      T=settimeout (zoomin,400);    }). MouseOver (function () {   if (t!=null) cleartimeout (t);   T=null;  

  

Method 2:jquery (requires version number greater than 1.2.2)
MouseEnter and MouseLeave event IE-specific functions, using jquery is a good solution to the compatibility problem. The principle of the function is triggered when the mouse enters the node area for the first time, and is not triggered when it is moved within the node area (between child nodes).

$ (' div '). Mouseout (function () {     cleartimeout (t);      T=settimeout (zoomin,400);    }). MouseOver (function () {   if (t!=null) cleartimeout (t);   T=null;  

  

jquery version >1.4 simplified notation:

$ (' div '). Mouseout (function () {     cleartimeout (t);      T=settimeout (zoomin,400);    }). MouseOver (function () {   if (t!=null) cleartimeout (t);   T=null;  

  

The flicker problem of jquery caused by mouseover,mouseout bubbling

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.