需要有关子菜单功能、超时的帮助

发布于 2024-09-19 02:33:02 字数 551 浏览 6 评论 0原文

我正在为 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"));
});

...(抱歉,该内联网的用户是新手...以防万一他们意外地翻转链接)

非常感谢任何帮助,谢谢

I'm working on this menu for a intranet system. I have a menu system which is partially working.

I have added the code to here: http://jsbin.com/eloxe3/8

The menu items with a light grey background have a submenu...whereas the others do not. I need some help in making the submenu disappear after I hover over a link without a submenu for 1 second.

I have this function that shows the submenu...& would like the new code to follow similar principles

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

...(Sorry the users of this Intranet are novices...just in case they acidentally rollover a link)

Any help is GREATLY APPRECIATED, Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤檠 2024-09-26 02:33:03

查看源代码,您应该将 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/

Looking at the source you should bind no-submenu with a hover state.

$('.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);
})

Im unsure weather delay would work with hide but you can give it a go, if it does not then try the following:

$('.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)
});

I may be wrong with this but you can give it a whirl anyway.

a small update to for clearTimeout

Try something along the lines of this instead:

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

Just not that $('.rtmenu').hide() may need to be $('.level2').hide() and you might be alittle better of being specific with .css('display','none')

Hover docs are here: http://api.jquery.com/hover/

后知后觉 2024-09-26 02:33:03

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

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

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

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

Take a look at the hoverIntent plugin. It triggers only if the cursor is hovering over an element.

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

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

This way the submenu won't be hidden if they accidentally move the cursor out of the menu and then quickly back in again, which is often the problem with submenus in my experience.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文