jQuery 切换故障
有没有办法避免 jQuery 的 slipToggle() 出现问题?
我有一个水平滑动菜单,当有人将鼠标悬停在链接上时,下面会出现滑动切换列表。
重点是,当我在 jQuery 加载之前将鼠标悬停在链接上时,一切都会以相反的方式进行。当我悬停时菜单会消失,当指针位于其他位置时菜单会显示。所以菜单是没有用的。
这是 jQuery 代码:
$('#nav li').hover(function(){
$(this).children('ul').slideToggle();
})
也许有一些条件,比如“如果 nav li 悬停并且 ul 不可见,则再次滑动切换”?但我不知道如何写。
多谢。
is there a way to avoid problems with jQuery's slideToggle()?
I have a horizontal-sliding menu when somebody hovers a link there'es slideToggling list beneath.
The point is when I hover my mouse over the link before jQuery loads - everthing works just opposite way. The menu disappears when I hover and shows when the pointer is somewhere else. So menu is useless.
Here's jQuery code:
$('#nav li').hover(function(){
$(this).children('ul').slideToggle();
})
Maybe some coditionals, something like "if nav li hovered and ul is invisible then slidetoggle once again"? But I'm not sure how to write it.
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了确保这里(与初始鼠标位置无关),您必须拆分
.hover()
在 < 上显式调用
.slideDown()
mouseenter
和.slideUp()
上mouseleave
,像这样:To be sure here (independent of initial mouse position), you have to split your
.hover()
to explicitly call.slideDown()
onmouseenter
and.slideUp()
onmouseleave
, like this: