A solution for bubbling problem based on similar events such as mouseout and mouseover _javascript techniques

Source: Internet
Author: User

Recently write something, more annoying, a pop-up layer, there are other elements above, the intention is that the mouse left the pop-up layer, perform some action, but in practice, the mouse left the pop-up layer elements, will also activate these actions. The method of stopping event bubbling for each browser is not valid.

Or we javaeye many, in a buddy blog found the following code:

Copy Code code as follows:

function Ismouseleaveorenter (e, handler) {
if (e.type!= ' mouseout ' && e.type!= ' MouseOver ') return false;
var RELTG = E.relatedtarget? E.relatedtarget:e.type = ' mouseout '? E.toelement:e.fromelement;
while (RELTG && RELTG!= handler)
RELTG = Reltg.parentnode;
Return (RELTG!= handler);
}

This method is to determine whether the current element is the element that is going to execute the Mouseout event, so that the above problem can be avoided.

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.