如何使用"jQuery下拉菜单"延迟隐藏菜单? [英] How to delay hiding of a menu with Jquery Dropdown Menu?

查看:228
本文介绍了如何使用"jQuery下拉菜单"延迟隐藏菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作正常的下拉菜单,但是我希望这样做,如果我将鼠标悬停在菜单上,它不会立即再次隐藏.所以基本上我想延迟一秒钟.

I have a dropdown menu that works fine, but I would like it so, that if I hover off the menu, it doesn't immediately hide again. So basically I would like a one second delay.

我已经阅读了有关setTimeout的信息,但不确定是否是我需要的?

I have read about setTimeout, but not sure if it is what I need?

$('#mainnav a').bind('mouseover', function()
{
    $(this).parents('li').children('ul').show();
});

$('#mainnav a').bind('mouseout', function()
{
    $(this).parents('li').children('ul').hide();
});

推荐答案

setTimeout正是您所需要的.

$('#mainnav a').bind('mouseout', function()
{
    var menu = this;
    setTimeout(function()
    {
        $(menu).parents('li').children('ul').hide();
    }, 1000);
});

这篇关于如何使用"jQuery下拉菜单"延迟隐藏菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆