Javascript 避免子菜单快速消失

Javascript 避免子菜单快速消失,javascript,jquery,menu,dhtml,Javascript,Jquery,Menu,Dhtml,全部, 如何修改以下菜单后面的javascript,以确保菜单项不再悬停时不会消失得太快?我希望子菜单在屏幕上至少等待2秒钟,然后它们才会消失 html背后的Javascript如下所示: var menu=function(){ var t=0,z=50,s=6,a; function dd(n){this.n=n; this.h=[]; this.c=[]} dd.prototype.init=function(p,c){ a=c; var w=do

全部,

如何修改以下菜单后面的javascript,以确保菜单项不再悬停时不会消失得太快?我希望子菜单在屏幕上至少等待2秒钟,然后它们才会消失

html背后的Javascript如下所示:

var menu=function(){
    var t=0,z=50,s=6,a;
    function dd(n){this.n=n; this.h=[]; this.c=[]}
    dd.prototype.init=function(p,c){
        a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), 
                     l=s.length, i=0;
        for(i;i<l;i++){
            var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
            h.onmouseover=new Function(this.n+'.st('+i+',true)');
            h.onmouseout=new Function(this.n+'.st('+i+')');
        }
    }
    dd.prototype.st=function(x,f){
        var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
        clearInterval(c.t); c.style.overflow='hidden';
        if(f){
            p.className+=' '+a;
            if(!c.mh){c.style.display='block'; c.style.height=''; 
                       c.mh=c.offsetHeight; c.style.height=0}
            if(c.mh==c.offsetHeight){c.style.overflow='visible'}
            else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
        }else{p.className=p.className.replace(a,''); 
                   c.t=setInterval(function(){sl(c,-1)},t)}
    }
    function sl(c,f){
        var h=c.offsetHeight;
        if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
            if(f==1){c.style.filter=''; c.style.opacity=1; 
                       c.style.overflow='visible'}
            clearInterval(c.t); return
        }
        var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
        c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
        c.style.height=h+(d*f)+'px'
    }
    return{dd:dd}
}();
var菜单=函数(){
变量t=0,z=50,s=6,a;
函数dd(n){this.n=n;this.h=[];this.c=[]}
dd.prototype.init=函数(p,c){
a=c;var w=document.getElementById(p),s=w.getElementsByTagName('ul'),
l=s.长度,i=0;

对于(i;i,可以在隐藏菜单之前使用jQuery的延迟函数

我看到了您的代码。您正在使用onmouseout事件。在该事件中,您可以等待2秒钟,然后隐藏下拉菜单:

$('#menu').hover(function () {
     // Mouse entered.
}, function () {
     // Mouse left (out)
     $(this).delay(2000).hide();
});

听起来很适合。

请提供一些示例代码。否则,很难提出任何建议……它们消失得如此之快有一个很好的原因。在UI land中,两秒钟是很长的时间。我的菜单保持打开状态的时间为7/10秒(700毫秒)鼠标离开后,有时甚至感觉太长,所以我们也添加了单击以关闭。单击菜单外会使其立即消失。我在js中如何调整此功能?您的插件不使用jQuery,JavaScript中没有内置的
delay
功能。有许多方法可以模仿,其中之一是setTimeout。我理解。只是不确定上面的JS代码中的哪个函数要使用setTimeout。如果您可以在本地尝试它,这将非常有用。谢谢
$('#menu').hover(function () {
     // Mouse entered.
}, function () {
     // Mouse left (out)
     $(this).delay(2000).hide();
});