2009-10-28 106 views
0

我正在使用jquery创建一个自定义下拉列表,下面的代码。我已经尝试了几乎工作的jquery超时效果,它的用法就像.idle(500);延迟下拉列表 - settimeout

我在下面的方法,一次下降所有的菜单。与不使用超时和嵌套的ishowmenu功能相比。

关于我能做什么的任何想法?

当使用idle()时,它首先显示div初始高度,然后放弃其余部分,我希望它会在500 ms后显示ALL。

我也试过这个下面,就立即

$(".main-heading").idle(2000).one("mouseover", showMenu); 

function showMenu() { 
    setTimeout(iShowMenu,500); 
    function iShowMenu(){ 
     $(".openMenu").each(HideMenu); //Hide any open menus 
     $(this).parent().addClass("openMenu"); 
     if (this.id == "flea-tick-nav") {//If it is out problem one 
      h = "280px"; //Or what ever the hight needs to be for that tab 
     }else{ 
      h="200px"; 
     } 
     $(".sub-drop-old", this.parentNode).show().animate({ 
      height: h 
     }, 500, "linear", function() { 
      $(this).parent(".main-menu").one("mouseleave", HideMenu); 
     }); 
    } 
} 
function HideMenu() { 
    $(".sub-drop-old:visible", this).stop().animate({ height: "0px" }, 500, "linear", function() { 
     $(this).hide().parent(".main-menu").removeClass("openMenu"); 
     $(".main-heading", this.parentNode).one("mouseover", showMenu); 
    }); 
} 
$(function() { 
    $(".main-heading").one("mouseover", showMenu); 
}); 

回答

1

dropddowns从我可以从你的问题收集,你想会发生一定的动画(下拉菜单的向下)经过一段时间后。我会做这个

一种方法是利用jQuery的动画功能,事实上,你可以传递任何属性/值对的,是动画

因此,对于你的代码,删除setTimeout(iShowMenu,500);,然后使用此代码该函数

$(".sub-drop-old", this.parentNode) 
     .animate({ 
     fakeproperty:'fakevalue' //<--- This is a fake property:value, can be anything 
     },{ 
      duration:500, //<--- the fake prop:val animation will delay the callback for 500ms 
      complete:function(){ //<--- this is the callback where the actual animation takes place 
      $(this).show().animate({ 
       height: h 
      }, 500, "linear", function() { 
       $(this).parent(".main-menu").one("mouseleave", HideMenu); 
      }); 
     }}); 

的主要部分的动画,你还需要内部功能iShowMenu的内容移动到外部函数showMenu

^h ope,帮助...

+0

啊,我明白你在做什么。聪明。我喜欢这样,只是动画,并使用完整的来调用它。看看如果你快速浏览它们,它们仍然滑落,想法? http://staging.petfooddirect.com:84/ – Coughlin 2009-10-28 14:46:05

+1

试试这个插件http://cherne.net/brian/resources/jquery.hoverIntent.html – ekhaled 2009-10-28 15:01:53