jquery SlideUp 菜单切换?

发布于 2024-09-13 14:14:05 字数 842 浏览 2 评论 0原文

我有一个向上滑动菜单,它的行为不稳定,有时如果我快速滑动它,它可能会上下滑动 4 或 5 次。在其他时候,如果我在正确加载之前将鼠标悬停在它上面,菜单将向上滑动并成为其“正常”状态,这样如果我将鼠标悬停在它上面,它就会在我有机会单击任何菜单项之前向下滑动。

这是代码:

$(document).ready(function(){
 var opened = false;
 $("#menu_box").hover(function(){

  if(opened){
   $("#menu_box").animate({"top": "+=97px"}, "200");
  }

  else{
   $("#menu_box").animate({"top": "-=97px"}, "200");
  }


  $("#menu_content").slideToggle("200");
  $("#menu_tab .close").toggle();
  opened = !opened;


 });
})

该代码最初是一个单击功能,而不是悬停功能,所以我尝试将其修改为以下内容:

$(document).ready(function(){
 $("#menu_box").hover(function(){

  $("#menu_box").toggle(function(){

   $("menu_box").animate({"top": "-=97px"}, "200");
   $("#menu_content").slide("200");

            });
 });
});

但这只是使菜单从右向左淡出 - 根本不滑动。

我哪里出错了?蒂亚!

I have a slideUp menu, which is acting erratically in that sometimes if I flick too quickly across it, it slides up and down maybe 4 or 5 times. At other times, if I hover over it before it's finished loading properly, the menu will slideUp and that becomes its "normal" state so that if I hover over it, it slides down before I have a chance to click any menu items.

Here is the code:

$(document).ready(function(){
 var opened = false;
 $("#menu_box").hover(function(){

  if(opened){
   $("#menu_box").animate({"top": "+=97px"}, "200");
  }

  else{
   $("#menu_box").animate({"top": "-=97px"}, "200");
  }


  $("#menu_content").slideToggle("200");
  $("#menu_tab .close").toggle();
  opened = !opened;


 });
})

The code was originally a click function, rather than hover, so I tried amending it to the following:

$(document).ready(function(){
 $("#menu_box").hover(function(){

  $("#menu_box").toggle(function(){

   $("menu_box").animate({"top": "-=97px"}, "200");
   $("#menu_content").slide("200");

            });
 });
});

But that just made the menu fade from right to left - not sliding at all.

Where am I going wrong? TIA!

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

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

发布评论

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

评论(1

盛夏已如深秋| 2024-09-20 14:14:05

使用绑定 mouseenter/mouseleave 而不是悬停修复了它!

Fixed it with bind mousenter/mouseleave instead of hover!

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