鼠标移动穿过重叠或嵌套区域时的事件计时
当我有嵌套对象时,鼠标经过时发生的事件的时间非常违反直觉且复杂。有人可以解释一下时间规则吗?
例如,当我嵌套 div
时,如下所示:
其中每个 div 都有onmouseover
和 onmouseout
属性以便它们触发事件,它们按以下顺序执行:
当鼠标移动 1 --> > 2
<块引用>鼠标悬停2
鼠标移动时2 --> 3
<块引用>鼠标悬停 2
鼠标悬停 3
鼠标悬停 2鼠标移动时 3 --> 4
<块引用>鼠标悬停 3
鼠标移出 2
鼠标悬停 4
鼠标悬停 2
鼠标悬停 3鼠标移动时 4 --> 5
<块引用>鼠标悬停 2
鼠标悬停 5
鼠标移出 3
鼠标悬停 4
鼠标移出 4
鼠标悬停 3
鼠标悬停 2鼠标移动时 5 --> 4
<块引用>鼠标悬停 5
鼠标移出 4
鼠标悬停 3
鼠标悬停 4
鼠标移出 2
鼠标移出 3
鼠标悬停 2鼠标移动时 4 --> 3
<块引用>鼠标悬停 4
鼠标悬停 3
鼠标悬停 2
鼠标移出 3
鼠标移开 2鼠标移动时 3 --> 2
<块引用>鼠标悬停 3
鼠标移出 2
鼠标悬停 2鼠标移动时2 --> 1
<块引用>鼠标悬停 2
我特别使用 Firefox 9.0。请告诉我网络浏览器之间是否存在差异。
When I have nested objects, the timing of events that occur when a mouse passes though is very counterintuitive and complex. Can someone explain the rules for the timing?
For example, when I have nested div
s like the following:
where each div has the onmouseover
and onmouseout
properties so that they fire events, they do so in the following order:
When the mouse moves 1 --> 2
mouseover 2
When the mouse moves 2 --> 3
mouseout 2
mouseover 3
mouseover 2When the mouse moves 3 --> 4
mouseout 3
mouseout 2
mouseover 4
mouseover 2
mouseover 3When the mouse moves 4 --> 5
mouseout 2
mouseover 5
mouseout 3
mouseover 4
mouseout 4
mouseover 3
mouseover 2When the mouse moves 5 --> 4
mouseout 5
mouseout 4
mouseover 3
mouseover 4
mouseout 2
mouseout 3
mouseover 2When the mouse moves 4 --> 3
mouseout 4
mouseover 3
mouseover 2
mouseout 3
mouseout 2When the mouse moves 3 --> 2
mouseout 3
mouseout 2
mouseover 2When the mouse moves 2 --> 1
mouseout 2
I am particularly using Firefox 9.0. Please let me know if there is difference between webbrowsers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我强烈建议您使用 mouseenter 和 mouseleave 事件。使用嵌套元素时,鼠标悬停和鼠标移出会很棘手。
来自文档:
另外,我建议使用并且我大部分时间都使用 jQuery Hover 帮助器,它绑定那些无错误的冒泡事件。
I highly recommend you to use mouseenter and mouseleave events. Mouseover and mouseout are tricky when using nested elements.
From docs:
Also I recommend using and I use most of times jQuery Hover helper which binds those non-buggy-bubbling events.