开发者

jquery slideUp menu toggle?

开发者 https://www.devze.com 2023-01-11 00:22 出处:网络
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

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;
开发者_Go百科 $("#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!


Fixed it with bind mousenter/mouseleave instead of hover!

0

精彩评论

暂无评论...
验证码 换一张
取 消