jQuery 切换故障

发布于 2024-10-02 14:54:11 字数 378 浏览 6 评论 0原文

有没有办法避免 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 技术交流群。

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

发布评论

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

评论(1

草莓味的萝莉 2024-10-09 14:54:11

为了确保这里(与初始鼠标位置无关),您必须拆分 .hover()在 < 上显式调用 .slideDown() mouseenter.slideUp()mouseleave,像这样:

$('#nav li').hover(function(){
  $(this).children('ul').slideDown();
}, function() {
  $(this).children('ul').slideUp();
});

To be sure here (independent of initial mouse position), you have to split your .hover() to explicitly call .slideDown() on mouseenter and .slideUp() on mouseleave, like this:

$('#nav li').hover(function(){
  $(this).children('ul').slideDown();
}, function() {
  $(this).children('ul').slideUp();
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文