jQuery MouseLeave 跨一组类?
我有以下 HTML
<div class="outer-field"></div>
<div class="outer-field"></div>
<div class="outer-field"></div>
<div class="outer-field"></div>
函数中使用的内容
jQuery('.outer-field').live('mouseleave',
function () {
console.log('in outer');
});
我的问题是,我只希望“mouseleave”函数在 ALL 之外时触发?此刻它会从一个移动到下一个 .outer-field
吗?
即,如果它在外面,我希望它触发一次,
我该怎么做?
I have the following HTML
<div class="outer-field"></div>
<div class="outer-field"></div>
<div class="outer-field"></div>
<div class="outer-field"></div>
Which is used within the function
jQuery('.outer-field').live('mouseleave',
function () {
console.log('in outer');
});
My problem is that I only want the "mouseleave" function to fire when it is outside ALL of these ? At the moment it fires moving from one to next .outer-field
?
i.e. I want it to fire once if it is outside
How can I do this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须将所有 div 封装在您监听鼠标离开的一个 div 中......
You have to encapsule all divs in one your listening for mouse leave...
如果您无法更改 HTML 结构(这将是一个更简单的解决方案),您需要通过包装 I'm 传递给 setTimeout 的函数来延迟 mouseout 代码的执行。将返回的 Id 存储在变量中,并在鼠标悬停在其中一个元素上时使用clearTimeout,这将取消计划的执行。
If you can't change the HTML structure (which would be a simpler solution), you need to delay the execution of the mouseout code by wrapping I'm a function passed to setTimeout. Store the returned I'd in a variable and use clearTimeout on mouseover of one of the elements, which will cancel the scheduled execution.