我的下拉菜单的内容关闭得太快了

时间:2014-01-03 18:20:16

标签: html css menu

我正在建立一个网站,我遇到了这个问题......当我鼠标悬停在一个li元素上并且显示子菜单时,我无法在其中点击任何内容,因为它关闭得非常快:/我发现了类似的问题和解决方案已经在这里尝试实现但没有奏效:/ (JSFiddle Link; http://jsfiddle.net/qbNLN/1

HTML code:

<ul class="main_navigation" role="menubar">
<li role="menuitem">
    <a href="#" class="link">Compre por Marcas</a>
    <div class="balloon balloon_big">
        <span class="balloon_top" style="left: 38px;"></span>
        <p class="base-title"><strong>Compre por Marcas</strong></p>
        <div class="menucolumns">
            <div class="column1">
                <ul class="submenuitems column1">
                    <li><a href="#" title="4 Plus Nutrition">4 Plus Nutrition</a></li>
                </ul>
            </div>
            <div class="column1">
                <ul class="submenuitems column1">
                    <li><a href="#" title="Hayabusa">Hayabusa</a></li>
                </ul>
            </div>
            <div class="column1">
                <ul class="submenuitems column1">
                    <li><a href="#" title="Pacific Health">Pacific Health</a></li>
                </ul>
            </div>
        </div>
    </div>
</li>
<li role="menuitem">
    <a href="#" class="link">Compre por Objetivo</a>
    <div class="balloon">
        <span class="balloon_top" style="left: 38px;"></span>
        <p class="base-title"><strong>Compre por Objetivo</strong></p>
        <ul class="submenuitems">
            <li><a href="/" class="main-submenu-lnk">Camisas</a></li>
        </ul>
    </div>
</li>
<li role="menuitem">
    <a href="#" class="link">Compre por Categoria</a>
    <div class="balloon">
        <span class="balloon_top" style="left: 38px;"></span>
        <p class="base-title"><strong>Compre por Categoria</strong></p>
        <ul class="submenuitems">
            <li><a href="/" class="main-submenu-lnk">Camisas</a></li>
        </ul>
    </div>
</li>

CSS代码:

            .main_navigation {
            margin: 0 auto;
            padding: 0;
            vertical-align: top;
            background: #304e89;
            border-left: rgba(0,0,0,0.4) 1px solid;
            border-right: rgba(255,255,255,0.1) 1px solid;
            font-size: 0;
            min-width:960px;
            width:1170px;
        }
        .main_navigation>li, .main_navigation .main_navigation-item {
            font-size: 12px;
            position: relative;
            vertical-align: top;
            float:left;
            list-style:none;
            list-style-type:none;
            font-weight:bold;
        }
        .main_navigation>li>a {
            color: #fff;
            padding: 11px 10px 9px;
            display: block;
            font-size: 13px;
            line-height: 20px;
            min-height: 20px;
            text-decoration: none;
            font-family: "DIN", sans-serif;
            background-color: #304e89;
            background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #304e89), color-stop(100%, #253e6f));
            background-image: -webkit-linear-gradient(top, #304e89, #253e6f);
            background-image: -moz-linear-gradient(top, #304e89, #253e6f);
            background-image: -ms-linear-gradient(top, #304e89, #253e6f);
            background-image: -o-linear-gradient(top, #304e89, #253e6f);
            background-image: linear-gradient(top, #304e89, #253e6f);
            border-left: rgba(255,255,255,0.1) 1px solid;
            border-right: rgba(0,0,0,0.4) 1px solid
        }
        .main_navigation>li> .link {
            text-transform:uppercase;
        }
        .main_navigation .balloon {
            display:none;
            position:absolute;
            top: 45px;
            left:0;
            z-index: 100;
        }
        .main_navigation li:hover .balloon_top {
            width: 0px;
            height: 0px;
            border: 0;
            padding: 0;
            display: block;
            position: absolute;
            top: 0
        }
        .main_navigation .balloon_top:after {
            border-bottom-color: #ececec
        }
        .balloon .base-title {
            margin: -15px -15px 0 -15px;
            padding: 10px 15px;
            background: #ececec;
            border-bottom: #ddd 1px solid
        }
        .main_navigation .balloon {
            top:50px;
            border: 1px solid #ccc;
            -webkit-border-radius:3px;
            -moz-border-radius:3px;
            border-radius:3px;
        }
        .balloon, .balloon_top, .balloon-right, .balloon-left, .balloon-bottom, .mini-modal {
            padding: 15px;
            position: relative;
            background: #fff;
            text-align: left;
            border: #ddd 1px solid;
            color: #333;
            font-size: 12px;
            font-family: Arial, sans-serif;
            text-transform: none;
            -moz-border-radius: 3px;
            -webkit-border-radius: 3px;
            border-radius: 3px
        }
        .balloon_top:after {
            width: 0;
            height: 0;
            content: " ";
            border: 7px solid rgba(255,255,255,0);
            border/*\**/: 7px solid transparent\9;
            border-bottom-color: #fff;
            border-top-width: 0;
            position: absolute;
            pointer-events: none;
            bottom: 100%;
            left: 50%;
            margin-left: -7px
        }
        .balloon_top:before {
            width: 0;
            height: 0;
            content: " ";
            border: 9px solid rgba(221,221,221,0);
            border/*\**/: 9px solid transparent\9;
            border-bottom-color: #ddd;
            border-top-width: 0;
            position: absolute;
            pointer-events: none;
            bottom: 100%;
            left: 50%;
            margin-left: -9px
        }
        .balloon-right:after {
            width: 0;
            height: 0;
            content: " ";
            border: 7px solid rgba(255,255,255,0);
            border/*\**/: 7px solid transparent\9;
            border-left-color: #fff;
            border-right-width: 0;
            position: absolute;
            pointer-events: none;
            left: 100%;
            top: 50%;
            margin-top: -7px
        }
        .balloon-right:before {
            width: 0;
            height: 0;
            content: " ";
            border: 9px solid rgba(221,221,221,0);
            border/*\**/: 9px solid transparent\9;
            border-left-color: #ddd;
            border-right-width: 0;
            position: absolute;
            pointer-events: none;
            left: 100%;
            top: 50%;
            margin-top: -9px
        }
        .balloon-left:after {
            width: 0;
            height: 0;
            content: " ";
            border: 7px solid rgba(255,255,255,0);
            border/*\**/: 7px solid transparent\9;
            border-right-color: #fff;
            border-left-width: 0;
            position: absolute;
            pointer-events: none;
            top: 50%;
            right: 100%;
            margin-top: -7px
        }
        .balloon-left:before {
            width: 0;
            height: 0;
            content: " ";
            border: 9px solid rgba(221,221,221,0);
            border/*\**/: 9px solid transparent\9;
            border-right-color: #ddd;
            border-left-width: 0;
            position: absolute;
            pointer-events: none;
            top: 50%;
            right: 100%;
            margin-top: -9px
        }
        .balloon-bottom:after {
            width: 0;
            height: 0;
            content: " ";
            border: 7px solid rgba(255,255,255,0);
            border/*\**/: 7px solid transparent\9;
            border-top-color: #fff;
            border-bottom-width: 0;
            position: absolute;
            pointer-events: none;
            top: 100%;
            left: 50%;
            margin-left: -7px
        }
        .balloon-bottom:before {
            width: 0;
            height: 0;
            content: " ";
            border: 9px solid rgba(221,221,221,0);
            border/*\**/: 9px solid transparent\9;
            border-top-color: #ddd;
            border-bottom-width: 0;
            position: absolute;
            pointer-events: none;
            top: 100%;
            left: 50%;
            margin-left: -9px
        }
        .main_navigation .balloon_big {
            width:1000px;
        }
        .main_navigation .balloon .submenuitems {
            list-style:none;
            list-style-type:none;
            padding:10px 0 0 0;
            margin:0;
        }
        .main_navigation .balloon .menucolumns {
            border:1px dashed #000;
            clear:both;
            overflow:hidden;
        }
        .main_navigation .balloon .menucolumns .column1 {
            float:left;
            min-width:150px;
            max-width:200px;
        }

谢谢你们,任何帮助都将不胜感激!

2 个答案:

答案 0 :(得分:3)

Pure-CSS解决方案: Fiddle

使用.main_navigation>li:hover .balloon代替.main_navigation>li a:hover + .balloon,即使鼠标悬在气球上,也可确保气球保持打开状态。

然后添加,

.balloon:before {
    display: block;
    content: "";
    width: 100%;
    height: 10px;
    position: absolute;
    top: -10px;
    left: 0;
}

在菜单和气球之间添加一个不可见的块。

答案 1 :(得分:0)

当你的鼠标命中时,你的菜单和下拉菜单之间会有间隙。

如果您想保持视觉感受,请使用https://github.com/briancherne/jquery-hoverIntent

或者,如果您只想尝试较小的js,请调整How to delay hiding of a menu with Jquery Dropdown Menu?,如下所示(您可以将1000更改为更大或更小的值)。

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