寻求有关单击时打开的垂直弹出菜单的帮助,然后保持打开状态,直到单击另一个菜单项(悬停时不会消失)。同样,一旦两者都已单击鼠标悬停状态,则在单击之前不会显示。下面是一个codepen链接 http://codepen.io/matriplett/pen/JoVdYz
html:
<nav class="nav" >
<ul id="main-menu" class="nav parent">
<li class="parent"><a href="#">Menu 1</a>
<ul class="sub-menu">
<li class=""><a href="#">sub 1</a></li>
<li class=""><a href="#">sub 2</a>
<ul class="sub-sub-menu">
<li class=""><a href="#">sub sub 1</a></li>
<li class=""><a href="#">sub sub 2</a></li>
<li class=""><a href="#">sub sub 3</a></li>
<li class=""><a href="#">sub sub 4</a></li>
</ul></li>
<li class=""><a href="#">sub 3</a></li>
<li class=""><a href="#">sub 4</a></li>
<li class=""><a href="#">sub 5</a></li>
</ul>
</li>
<li class="parent"><a href="#">Menu 2</a>
<ul class="sub-menu">
<li class=""><a href="#">sub 1</a></li>
<li class=""><a href="#">sub 2</a>
<ul class="sub-sub-menu">
<li class=""><a href="#">sub sub 1</a></li>
<li class=""><a href="#">sub sub 2</a></li>
<li class=""><a href="#">sub sub 3</a></li>
<li class=""><a href="#">sub sub 4</a></li>
</ul>
</li>
<li class=""><a href="#">sub 3</a>
<ul class="sub-sub-menu">
<li class=""><a href="#">sub sub 1</a></li>
<li class=""><a href="#">sub sub 2</a></li>
<li class=""><a href="#">sub sub 3</a></li>
<li class=""><a href="#">sub sub 4</a></li>
</ul>
</li>
</ul>
</li>
<li class=""><a href="#">Menu 3</a></li>
<li class=""><a href="#">Menu 4</a></li>
</ul>
</nav>
scss
.nav {
border: 0;
padding:2%;
ul {
}
li {
position: relative;
text-transform: uppercase;
font-size: 1em;
list-style:none;
a {
border-bottom: 0;
line-height: 1.2;
color:#000;
text-decoration:none;
&:hover, &:focus {
color: #56a0d3;
}
}
ul.sub-menu{
margin-left:40px;
margin-top:-18px;
border-top: 0;
position: absolute;
visibility: hidden;
z-index: 8999;
display:block;
line-height:2;
li {
a {
margin-top:0;
padding-left: 10px;
border-right: 0;
display: block;
line-height: 1.2;
color: #56aod3;
&:hover,
&:focus {color:red;}
&:link {}
}
}
}
/* showing sub-menus */
&:hover > ul {
top: auto;
visibility:visible;
}
} /* end .menu ul li */
/* highlight current page */
li.current-menu-item,
li.current_page_item,
li.current_page_ancestor {
a { color:#56a0d3;}
} /* end current highlighters */
sub-sub-menu ul li a {
margin-left:300px;
}
} /* end .nav */
/* keep home page nav open on click*/
$('.sub-menu').hide(); //Hide children by default
$('.parent').children().click(function(){
$(this).children('.sub-menu').slideToggle('fast');
}).children('.sub-menu').click(function (event) {
event.stopPropagation();
});