将鼠标移动到主菜单上不会使子菜单保持打开状态

时间:2015-12-26 04:30:44

标签: jquery css

我正在使用JQuery superfish创建菜单,并且还使用Cufon功能。以下是我写的代码:

<html>
<head>
<style>
/* menu */

/*** ESSENTIAL STYLES ***/
.sf-menu, .sf-menu * {
    margin: 0;
    padding: 0;
    list-style: none;
}

.sf-menu ul {
    position: absolute;
    top: -999em;
    width: 10em; /* left offset of submenus need to match (see below) */
}
.sf-menu ul li {
    width: 100%;
}
.sf-menu li:hover {
    visibility:     inherit; /* fixes IE7 'sticky bug' */
}
.sf-menu li {
    float: left;
    position:       relative;
}
.sf-menu a {
    display:        block;
    position:       relative;
}

.sf-menu li:hover ul,
.sf-menu li.sfHover ul {
    left:           0;
    top:            2.5em; /* match top ul list item height */
    z-index:        99;
}
ul.sf-menu li:hover li ul,
ul.sf-menu li.sfHover li ul {
    top:            -999em;
}
ul.sf-menu li li:hover ul,
ul.sf-menu li li.sfHover ul {
    left:           10em; /* match ul width */
    top:            0;
}
ul.sf-menu li li:hover li ul,
ul.sf-menu li li.sfHover li ul {
    top:            -999em;
}
ul.sf-menu li li li:hover ul,
ul.sf-menu li li li.sfHover ul {
    left:           10em; /* match ul width */
    top:            0;
}
/*** DEMO SKIN ***/
.sf-menu {
    float:  left;
    margin-top: 1px;
    padding-top: 3px;
    padding-left: 10px;
    padding-bottom: 5px;
}
.sf-menu a {
    padding-left: 10px;
    padding: 8px 8px 8px 8px;
    text-decoration:none;
    cursor: pointer;

}
.sf-menu ul {
    -moz-border-radius: 4px;
    border-radius: 4px;
    -webkit-border-radius: 4px;
}


.sf-menu li {
    -moz-border-radius: 2px;
    border-radius: 2px;
    -webkit-border-radius: 2px;
    margin-bottom: 0px;
    margin-right: 5px;

}
.sf-menu li a {
    font-size: 11px;
    font-weight: normal;
    color: #0f63a4;
}
.sf-menu li a:hover{
    color: #fff;
    background: #0f63a4;
    -moz-border-radius: 2px;
    border-radius: 2px;
    -webkit-border-radius: 2px;
}

.sf menu li li{
    margin-left: 2px;
    background: #0f63a4;
    padding-top: 10px;

}

.sf-menu li li a {
    background: #fff;
    font-size: 11px;
    color: #0f63a4;
}
.sf-menu li li:last-child a {
    background: #fff;
    font-size: 11px;
    color: #0f63a4;
    -moz-border-radius: 2px;
    border-radius: 2px;
    -webkit-border-radius: 2px;

}

.sf-menu li li a:hover {
    color: #fff;
    background: #0f63a4;
    -moz-border-radius: 2px;
    border-radius: 2px;
    -webkit-border-radius: 2px;
}
.sf-menu li li li {
    margin-left: 3px;
}
*/
/* 3rd level bg */
/*
.sf-menu li li li a { 
    background: url(../images/nav-bg-hover.png) repeat-x left top #cdcdcd;
    -moz-border-radius: 2px;
    border-radius: 2px;
    -webkit-border-radius: 2px;
    border: 1px solid #eee;
}
*/
.sf-menu li li li a:hover { /* 3rd level bg */
    background: #fff;

    color: #0f63a4;

}
/*
.sf-menu li:hover, .sf-menu li.sfHover,
.sf-menu a:focus, .sf-menu a:hover{
    background: url(../images/nav-bg-hover.png) repeat-x left top #cdcdcd;
    color: #fff;
}
*/
/*** arrows **/
.sf-menu a.sf-with-ul {
    padding-right:  2.25em;
    min-width:      1px; /* trigger IE7 hasLayout so spans position accurately */
}
.sf-sub-indicator {
    position:       absolute;
    display:        block;
    right:          .75em;
    top:            1.05em; /* IE6 only */
    width:          10px;
    height:         10px;
    text-indent:    -999em;
    overflow:       hidden;
    background:     url('../images/arrows-ffffff.png') no-repeat -10px -100px; /* 8-bit indexed alpha png. IE6 gets solid image only */
}
a > .sf-sub-indicator {  /* give all except IE6 the correct values */
    top:            .8em;
    background-position: 0 -100px; /* use translucent arrow for modern browsers*/
}
/* apply hovers to modern browsers */
a:focus > .sf-sub-indicator,
a:hover > .sf-sub-indicator,
a:active > .sf-sub-indicator,
li:hover > a > .sf-sub-indicator,
li.sfHover > a > .sf-sub-indicator {
    background-position: -10px -100px; /* arrow hovers for modern browsers*/
}
/* point right for anchors in subs */
.sf-menu ul .sf-sub-indicator { background-position:  -10px 0; }
.sf-menu ul a > .sf-sub-indicator { background-position:  0 0; }
/* apply hovers to modern browsers */
.sf-menu ul a:focus > .sf-sub-indicator,
.sf-menu ul a:hover > .sf-sub-indicator,
.sf-menu ul a:active > .sf-sub-indicator,
.sf-menu ul li:hover > a > .sf-sub-indicator,
.sf-menu ul li.sfHover > a > .sf-sub-indicator {
    background-position: -10px 0; /* arrow hovers for modern browsers*/
}
/*** shadows for all but IE6 ***/
.sf-shadow ul {
    background: url(../images/shadow.png) no-repeat bottom right;
    padding: 0 8px 9px 0;
    -moz-border-radius-bottomleft: 17px;
    -moz-border-radius-topright: 17px;
    -webkit-border-top-right-radius: 17px;
    -webkit-border-bottom-left-radius: 17px;
}
.sf-shadow ul.sf-shadow-off {
    background: transparent;
}
.sf-menu .second-level {
    padding-top: 2px;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/cufon/1.09i/cufon-yui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.hoverintent/1.7.0/jquery.hoverIntent.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/superfish/1.7.7/js/superfish.js"></script>
<script src="Gotham_HTF_700.font.js"></script>
<script type="text/javascript">
$(document).ready(function()
        {
    if (jQuery('ul.sf-menu') && jQuery.superfish) {
                jQuery('ul.sf-menu').superfish({ 
                    pathClass:  'current' 
                });
            }
    });
   Cufon.replace('h3:not(.nocufon)');
        Cufon.replace('.breadcrumbs .current h2',{
            textShadow: '1px 1px #333',
        });

   Cufon.replace('.sf-menu li a', {
            hover: true
        });

        $('ul.sf-menu').superfish({ 
            delay:       100,                            
            animation:   {opacity:'show',height:'show'},
            speed:       'fast',
            autoArrows:  false,
            dropShadows: false
        }); 
</script>
</head>
<body>
<div class="column span-20 menu" style="width:80%">
         <ul class="sf-menu">
              <li>
                     <a>Configuration</a>
                 <ul>   
                    <li> 
                        <a href="../codeMapping/list">Code Mapping</a>
                    </li>
                    <li>
                        <a href="../codeType/list">Code Type</a>
                    </li>
                    <li>
                      <a href="../errorMapping/list">Error Code Mapping</a>
                    </li>
                    <li>
                      <a href="../propertyCodeMapping/list">Property Code Mapping</a>
                    </li>
                    <li>
                      <a href="../auth/logout">Logout</a>
                    </li>
                 </ul>
              </li> 
            </ul>

    </div>
</body> 
</html>

当我在浏览器中执行代码时,单击主菜单不会保持子菜单打开。请帮助我解决此问题。

1 个答案:

答案 0 :(得分:0)

您的“配置”及其子菜单之间有差距

只需将margin-top: -13px;添加到<ul>代码并查看。

工作小提琴:https://jsfiddle.net/a4938kqw/

希望这有助于。