使用 setTimeout、mouseenter、mouseleave 的 jQuery 导航菜单
我无法发现 此 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,使用
var n = ...
而不仅仅是n = ...
来创建局部变量。但是,您当前访问
n
变量的方式(作为超时后评估的字符串)需要全局变量。最好将其定义为可以利用本地范围内的变量的函数:演示
Yes, use
var n = ...
instead of justn = ...
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:Demo