简体   繁体   English

如何在现代浏览器中使用mousein事件?

[英]How do I use the mousein event in modern browsers?

There are two pointer exit events: mouseout and mouseleave . 有两个指针退出事件: mouseoutmouseleave

The difference between the two is that mouseleave fires only when the pointer leaves the watched element, while mouseout fires when the pointer leaves the watched element or any of its children . 两者之间的区别是, mouseleave仅在指针离开被监视元素时才触发,而mouseout在指针离开被监视元素或其任何子元素时才触发。

When you move the pointer in and out of an element, mouseleave fires exactly once, while mouseout may fire more than once, depending on the number of children you hovered over. 将指针移入和移出元素时, mouseleave会触发一次,而mouseout可能会触发一次以上,具体取决于您悬停的子代数。

The question is: where is the mousein equivalent of mouseout ? 问题是: mouseinmousein等同于mouseout On MDN, only mouseleave , mouseout and mouseenter are documented . 在MDN,只有mouseleavemouseoutmouseenter 被记录在案

For a rare use case, I need to run code on every element that the pointer enters, including dynamically created ones. 对于一个罕见的用例,我需要在指针输入的每个元素上运行代码,包括动态创建的元素。 mousein would solve this for me, but it does not seem to exist anymore. mousein可以为我解决这个问题,但是似乎已经不存在了。

The question is: where is the mousein equivalent of mouseout 问题是: mousein等同于mouseout在哪里

The corresponding event to mouseout is mouseover , and for mouseleave it is mouseenter . mouseout的相应事件是mouseovermouseleave事件是mouseenter

Their main difference is that that mouseleave / mouseenter does not bubble, which is well explained in eg MDN , but in short 它们的主要区别在于mouseleave / mouseenter不会冒泡,这在MDN中得到了很好的解释,但总之

  • mouseleave is fired when the pointer has exited the element and all of its descendants, whereas mouseout is fired when the pointer leaves the element or leaves one of the element's descendants (even if the pointer is still within the element). 当指针退出元素及其所有后代时,将触发mouseleave ;而当指针离开元素或元素的后代之一(即使指针仍位于元素内)时,将触发mouseout

  • mouseover , it differs from mouseenter in that it doesn't bubble and that it isn't sent when the pointer is moved from one of its descendants' physical space to its own physical space. mouseover ,它与mouseenter不同之处在于它不会冒泡,并且当指针从其后代的一个物理空间移动到其自己的物理空间时也不会发送。

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

相关问题 现代浏览器中的鼠标滚轮事件 - Mousewheel event in modern browsers 如何正确使用postMessage与html5和现代浏览器进行跨域消息传递? 我仍然得到错误 - How to properly use postMessage to do cross-domain messaging with html5 and modern browsers ? I still get errors 如何在Chrome和其他现代浏览器中使用离线事件和在线事件? - How can I use onoffline and ononline events in Chrome and other modern browsers? 我可以在使用JavaScript的现代浏览器中使用或打开“插入”插入符号吗? - Can I use or turn on the 'insert' caret in modern browsers using javascript? 如何在旧版浏览器中使用JSON? - How do I use JSON in older browsers? 现代浏览器如何实现 JS Array,特别是添加元素? - How do modern browsers implement JS Array, specifically adding elements? 如何在现代浏览器中全局监听获取完成? - How can I globally listen for fetch completion in modern browsers? 如何在现代浏览器中实现lodash _.remove函数? - How can I implement the lodash _.remove function in modern browsers? 如何解释浏览器之间不同的“存储”事件行为? - How do I account for different “storage” event behavior between browsers? 如何在所有浏览器中使用CSS.escape()或同等功能? - How do I use CSS.escape() or equivalent for all browsers?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM