如何一次检测两个元素上的mouseleave()? [英] How to detect mouseleave() on two elements at once?

查看:73
本文介绍了如何一次检测两个元素上的mouseleave()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

答案可以在普通js或jQuery中.如果用户不再将鼠标悬停在ID为"myLink"的链接或ID为"mySpan"的跨度上,我想隐藏ID为"myDiv"的div.如果用户将鼠标悬停在任一元素"myDiv"上仍会显示,但用户第二次未将鼠标悬停在这两个元素上(与用户的鼠标先离开哪个元素无关),"myDiv"将从脸上消失的存在.

Answer can be in vanilla js or jQuery. I want to hide a div with the id "myDiv" if the user is no longer hovering over a link with the id "myLink" or a span with the id "mySpan". If the user has his mouse over either element "myDiv" will still show, but the second the user is not hover over either of the two (doesn't matter which element the user's mouse leaves first) "myDiv" will disappear from the face of existence.

换句话说,这就是我检测到鼠标停留在一个元素上的方式:

In other words this is how I detect mouse leave on one element:

$('#someElement').mouseleave(function() {

   // do something

});

但是怎么说(以一种切实可行的方式):

but how to say (in a way that will actually work):

$('#someElement').mouseleave() || $('#someOtherElement').mouseleave()) {

   // do something

});

如何检测到这个?

推荐答案

您可以使用多重选择器:

$("#someElement, #someOtherElement").mouseleave(function() {
   // Do something.
});

这篇关于如何一次检测两个元素上的mouseleave()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆