开发者

Why is onMouseOver event fired when the mouse only moves into an inner element?

开发者 https://www.devze.com 2023-03-06 07:18 出处:网络
When the mouse hovers into the inner element, the mouseOut event for the outer element is fired first, then the mouseOver element for inner element is fired, then the mouseOver element for the inner e

When the mouse hovers into the inner element, the mouseOut event for the outer element is fired first, then the mouseOver element for inner element is fired, then the mouseOver element for the inner element is fired last.

Why does t开发者_JS百科his happen? Because the inner element technically is still inside of the outer element, so the mouse doesn't leave the outer element when it moves into the inner element. Is there a way to prevent that?

Full example here: http://jsfiddle.net/pMCeu/4/


To avoid this you should use mouseenter and mouseleave instead of mouseover and mouseout.

It is due to event bubbling. take a look at this post for a little more info.


Hi the solution above is correct and complete. but you can also use mousemove event

0

精彩评论

暂无评论...
验证码 换一张
取 消