[英]How do I use the mousein event in modern browsers?
There are two pointer exit events: mouseout
and mouseleave
. 有两个指针退出事件:
mouseout
和mouseleave
。
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
? 问题是:
mousein
在mousein
等同于mouseout
? On MDN, only mouseleave
, mouseout
and mouseenter
are documented . 在MDN,只有
mouseleave
, mouseout
和mouseenter
被记录在案 。
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 ofmouseout
问题是:
mousein
等同于mouseout
在哪里
The corresponding event to mouseout
is mouseover
, and for mouseleave
it is mouseenter
. mouseout
的相应事件是mouseover
, mouseleave
事件是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.