【问题标题】:Help needed with submenu functionality, Timeout子菜单功能需要帮助,超时
【发布时间】:2011-04-12 02:37:41
【问题描述】:

我正在为 Intranet 系统开发此菜单。我有一个部分工作的菜单系统。

我已在此处添加代码:http://jsbin.com/eloxe3/8

浅灰色背景的菜单项有一个子菜单……而其他的则没有。在我将鼠标悬停在没有子菜单的链接上 1 秒钟后,我需要一些帮助才能使子菜单消失。

我有这个显示子菜单的功能...&希望新代码遵循类似的原则

$(".menu-arrow").hover(function(){
    $.data(this, "timer", setTimeout($.proxy(function() {
       $(this).click();
   },this),500));
},function(){
    clearTimeout($.data(this, "timer"));
});

...(对不起,这个 Intranet 的用户是新手...以防万一他们突然翻转链接)

非常感谢任何帮助,谢谢

【问题讨论】:

  • 对我来说,菜单仅包含一个链接(客户).. 在 Windows 7 上使用 Chrome 6
  • @Litso - 请点击客户链接查看菜单
  • 嘿,我已经习惯了悬停菜单,我并没有为此做好准备。愚蠢的我。

标签: jquery timeout hover delay


【解决方案1】:

看看hoverIntent plugin。仅当光标悬停在元素上时才会触发。

var hideSubmenus = function () {
    $('.rtmenu').hide()
};

$(".no-submenu").hoverIntent({
    over: hideSubmenus,
    out: function () { /* do nothing */ }
});

这样子菜单不会被隐藏,如果他们不小心将光标移出菜单然后又很快又回到菜单中,根据我的经验,这通常是子菜单的问题。

【讨论】:

    【解决方案2】:

    查看源代码,您应该将no-submenu 与悬停状态绑定。

    $('.no-submenu').bind('mouseenter',function(){
        //at this point the mouse is over a link with no submenu.
        //So we close all submenus
        $('.rtmenu').hide().delay(1000);
    })
    

    我不确定天气延迟是否适用于 hide,但您可以试一试,如果没有,请尝试以下操作:

    $('.no-submenu').bind('mouseenter',function(){
        //at this point the mouse is over a link with no submenu.
        //So we close all submenus
    
        var T = setTimeout(function(){
             $('.rtmenu').hide();
             clearTimeout(T);
        },1000)
    });
    

    我可能错了,但无论如何你可以试一试。

    clearTimeout 的小更新

    尝试类似的方法:

    var _TimeOut;
    $('.no-submenu').hover(,function(){
        var _TimeOut = setTimeout(function(){$('.rtmenu').hide();},1000)
    },function(){
        clearTimeout(_TimeOut);
    });
    

    不是$('.rtmenu').hide() 可能需要是$('.level2').hide() 并且你可能会更好地使用.css('display','none')

    悬停文档在这里:http://api.jquery.com/hover/

    【讨论】:

    • 感谢您的第二个代码 sn-p 工作...虽然当鼠标离开 a.no-submenu 时如何清除超时?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-31
    相关资源
    最近更新 更多