【问题标题】:jquery dropline to hold second when mouse is hover outjquery dropline 在鼠标悬停时保持第二个
【发布时间】:2011-10-01 03:05:27
【问题描述】:

有没有办法在this dropline menu 上获得此行为?当鼠标从菜单项悬停时,需要第二级或第三级保持活动状态一秒钟。

【问题讨论】:

    标签: javascript jquery menu hover


    【解决方案1】:

    为了澄清,您正在寻找对鼠标移动的某种延迟反应?如果是这样,请查看这个 jQuery hoverintent 插件:http://cherne.net/brian/resources/jquery.hoverIntent.html

    编辑:我认为您需要编辑您的菜单脚本以将任何 .hover 实例替换为 .hoverIntent。我在 jsfiddle 中测试时遇到了麻烦,但看看它是否有效:

    var droplinemenu={
    
    arrowimage: {classname: 'downarrowclass', src:'http://www.odzaci.rs/wp-content/themes/typo/images/down.gif', leftpadding: 5}, //customize down arrow image
    animateduration: {over: 200, out: 300}, //duration of slide in/ out animation, in milliseconds
    
    buildmenu:function(menuid){
        jQuery(document).ready(function($){
            var $mainmenu=$("#"+menuid+">ul")
            var $headers=$mainmenu.find("ul").parent()
            $headers.each(function(i){
                var $curobj=$(this)
                var $subul=$(this).find('ul:eq(0)')
                this._dimensions={h:$curobj.find('a:eq(0)').outerHeight()}
                this.istopheader=$curobj.parents("ul").length==1? true : false
                if (!this.istopheader)
                    $subul.css({left:0, top:this._dimensions.h})
                var $innerheader=$curobj.children('a').eq(0)
                $innerheader=($innerheader.children().eq(0).is('span'))? $innerheader.children().eq(0) : $innerheader //if header contains inner SPAN, use that
                $innerheader.append(
                    '<img src="'+ droplinemenu.arrowimage.src
                    +'" class="' + droplinemenu.arrowimage.classname
                    + '" style="border:0; padding-left: '+droplinemenu.arrowimage.leftpadding+'px" />'
                )
    
                // THIS IS THE PART I REPLACED
    
                var config = {    
         over: function(e){
                var $targetul=$(this).children("ul:eq(0)")
                if ($targetul.queue().length<=1) //if 1 or less queued animations
                    if (this.istopheader)
                        $targetul.css({left: $mainmenu.offset().left, top: $mainmenu.offset().top+this._dimensions.h})
                    if (document.all && !window.XMLHttpRequest) //detect IE6 or less, fix issue with overflow
                        $mainmenu.find('ul').css({overflow: (this.istopheader)? 'hidden' : 'visible'})
                    $targetul.slideDown(droplinemenu.animateduration.over)
            },
    timeout: 1000, // number = milliseconds delay before onMouseOut    
    out: function(e){
                var $targetul=$(this).children("ul:eq(0)")
                $targetul.slideUp(droplinemenu.animateduration.out)
            }
    };
    
    $curobj.hoverIntent( config );
    
    
    
    
            }) //end $headers.each()
            $mainmenu.find("ul").css({display:'none', visibility:'visible', width:$mainmenu.width()})
        }) //end document.ready
    }
    }
    

    【讨论】:

    • thx 回答,但我不知道如何将此插件合并到此脚本中。让我困惑使用什么选择器,尝试了几个选择器但没有成功。我尝试使用带有配置对象的 hoverIntent,但是没有结果。在我的标题(悬停意图脚本)中调用外部脚本,然后在脚本标签中添加上面提到的插件页面的脚本代码。当鼠标离开菜单链接时,没有任何延迟 500 毫秒(子菜单消失瞬间)就像插件页面上的示例一样。有什么问题?
    • 工作得很好,tnx 你能看到这个吗,请我也和这个堆栈一下:-( link
    猜你喜欢
    • 1970-01-01
    • 2013-07-16
    • 1970-01-01
    • 2013-11-26
    • 1970-01-01
    • 2011-02-06
    • 2011-08-04
    • 1970-01-01
    • 2011-11-26
    相关资源
    最近更新 更多