使用 setTimeout、mouseenter、mouseleave 的 jQuery 导航菜单

发布于 2024-12-21 09:26:10 字数 206 浏览 10 评论 0原文

我无法发现 此 jQuery 菜单 在三个主选项卡之间悬停时中断的问题。如果我将鼠标悬停在菜单中,然后一直悬停在选择另一个选项卡之前,菜单就会起作用... 我认为问题可能与变量的范围(在 jQuery 中称为“n”)或 setTimeout() 方法有关。

I'm having trouble spotting an issue where this jQuery menu breaks when hovering between the three main tabs. The menu works if i hover in, then hover all the way out before selecting another tab...
I think the problem may have to do with scope of a variable (called "n" in the jQuery) or the setTimeout() method.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

上课铃就是安魂曲 2024-12-28 09:26:10

是的,使用 var n = ... 而不仅仅是 n = ... 来创建局部变量。

但是,您当前访问 n 变量的方式(作为超时后评估的字符串)需要全局变量。最好将其定义为可以利用本地范围内的变量的函数:

setTimeout(function() { $(n).hide(); }, 150);

演示

Yes, use var n = ... instead of just n = ... to create a local variable.

The way you're currently accessing the n variable, as a string being evaluated after the timeout, requires a global variable, however. It's better if you define it as a function that can draw upon variables from the local scope:

setTimeout(function() { $(n).hide(); }, 150);

Demo

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