简体   繁体   English

为什么当鼠标仅移动到内部元素时会触发 onMouseOver 事件?

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

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.当鼠标悬停到内元件中, mouseOut用于外部元件事件首先被烧成,则mouseOver于内部元件部件发射,那么mouseOver用于内部元件元件最后烧制。

Why does this 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/完整示例: http : //jsfiddle.net/pMCeu/4/

To avoid this you should use mouseenter and mouseleave instead of mouseover and mouseout.为避免这种情况,您应该使用 mouseenter 和 mouseleave 而不是 mouseover 和 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但你也可以使用 mousemove 事件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Onmouseover事件在未预期时触发 - Onmouseover event is fired when not expected 在ios的Safari浏览器中,当有一个“ onclick”内联孩子时,有一个“ onmouseover”内联父母时,为什么单击该孩子时触发了mouseover事件? - In safari of ios, when there is a “onclick” inline a child, and a “onmouseover” inline a parent, why mouseover event fired when click the child? 当鼠标移动到svg路径元素内时,mouseout / mouseleave会被触发 - mouseout/mouseleave gets fired when mouse moves INSIDE the svg path element 使用JavaScript,为什么我的onmouseover事件没有被触发? - Using javascript, why is my onmouseover event not being fired? 为什么鼠标移动时 mousemove 事件中的 event.pageY 无法更新? - Why the event.pageY in mousemove event could not be updated when mouse moves? CSS:hover仅在鼠标移动时起作用 - CSS :hover works only when mouse moves Angular 仅在鼠标移动时绑定 - Angular bind only when mouse moves 鼠标传递选项时选择标签事件/ onmouseover选择选项 - select tag event when mouse pass on option / select option with onmouseover 按下和释放鼠标按钮时会触发鼠标事件“mousemove” - Mouse event “mousemove” gets fired when pressing and releasing mouse buttons 在循环中创建动态 div 元素并附加事件处理程序时,仅为最后一个元素触发事件 - When creating dynamic div elements in a loop and attaching event handlers, event is fired for last element only
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM