jQuery MouseLeave 跨一组类?

发布于 2024-11-25 13:31:08 字数 499 浏览 4 评论 0原文

我有以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风向决定发型 2024-12-02 13:31:08

您必须将所有 div 封装在您监听鼠标离开的一个 div 中......

You have to encapsule all divs in one your listening for mouse leave...

烟柳画桥 2024-12-02 13:31:08

如果您无法更改 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文