使用 jQuery/Javascript,如何检查鼠标在 MouseLeave
事件后悬停的第一个元素?
基本上,我想从元素数组中检查鼠标是否在这些元素上滚动。
我正在尝试使用 event.relatedTarget
。
有什么帮助吗?
最佳答案
存在一个relatedTarget
鼠标事件属性
The
MouseEvent.relatedTarget
read-only property is the secondary target for the mouse event, if there is one
对于mouseleave
,它指向输入的元素。
所以你可以这样做
$('element').mouseleave(function(event){
// assuming that allowedList holds the array of allowed elements
if ( allowedList.indexOf( event.relatedTarget ) > -1 ){
// found
} else {
// not found
}
});
关于javascript - 获取 MouseLeave 事件后鼠标悬停的第一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10366149/