Home  >  Article  >  Web Front-end  >  Solution to javascript mouseover, mouseout stop event bubbling_javascript skills

Solution to javascript mouseover, mouseout stop event bubbling_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:54:381290browse

There are onmouseleave and onmouseenter in IE, but it is still a headache for web developers who want to be compatible with major browsers.
Although there are some strategies against Mozilla Firefox on the Internet, the amount of code is not optimistic.
I wanted to find a better solution, so I searched through domestic websites, big and small, but found nothing. I had to bite the bullet and read foreign websites. The result was ideal, because there is relatedTarget in W3C, so I came up with the following Solution:

Copy code The code is 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);
}

Make the above judgment in onmouseover and onmouseout.
Author: lxsgoodluck
Statement:
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