认为我在正确的轨道上,但是subLink
当鼠标离开子链接菜单项并将鼠标悬停在非子链接上时需要关闭栏,subLink
但如果其子链接到子链接则不关闭(希望这是有道理的)。
subLink
例如,如果鼠标从子链接悬停状态悬停(例如),即 Home 或 Contact 将不会打开该栏并将其关闭。
我知道目前mouseleave是整体的#main-nav
,但我被困在如何去做这件事上,可能真的很简单,但是嘿必须从某个地方开始吧?只是为了让大家知道我从tutplus采购了这个菜单,并试图重新创建我自己的菜单,谢谢。
请在下面查看我当前的代码:
CSS:
html, body {
background: #2d2620;
text-align: center;
margin: 0px;
height: 100%;
width: 100%;
}
#wrap {
margin-left: auto;
margin-right: auto;
width: 900px;
position: relative;
background: url(body.png) center no-repeat;
min-height: 600px;
}
#body-image {
margin-top: 60px;
}
#main-nav {
margin: 0px 0px 0px 2px;
text-align: left;
min-height: 25px;
padding-top: 10px;
padding-left: 0px;
}
#main-handle {
width: 605px;
float: right;
margin-top: -1px;
}
#main-nav li {
display: inline;
list-style: none;
}
#main-nav li a {
margin-right: 5px;
font-size: 15px;
text-decoration: none;
color: #f2f2f2;
font-family: Arial, Helvetica, sans-serif;
text-transform: uppercase;
font-weight: bold;
padding: 10px;
outline: 0;
position: relative;
top: -2px;
}
#main-nav li a:hover, #main-nav li a.active {
background: #514539;
}
#sub-link-bar {
background: #514539;
min-height: 1px;
border-bottom: #645546 1px solid;
}
.sub-links {
display: none;
position: absolute;
width: 100%;
text-align: left;
left: 0px;
}
#main-nav li .sub-links li a:hover{
background: #2d2620;
}
#main-nav li a.close{
display: none;
position: absolute;
}
#main-nav li a.close:hover{
background: #900;
}
.round {
display:block
}
.round * {
display:block;
height:1px;
overflow:hidden;
font-size:.01em;
background:#645546
}
.round1 {
margin-left:3px;
margin-right:3px;
padding-left:1px;
padding-right:1px;
border-left:1px solid #443a30;
border-right:1px solid #443a30;
background:#56493c
}
.round2 {
margin-left:1px;
margin-right:1px;
padding-right:1px;
padding-left:1px;
border-left:1px solid #322a23;
border-right:1px solid #322a23;
background:#594c3e
}
.round3 {
margin-left:1px;
margin-right:1px;
border-left:1px solid #594c3e;
border-right:1px solid #594c3e;
}
.round4 {
border-left:1px solid #443a30;
border-right:1px solid #443a30
}
.round5 {
border-left:1px solid #56493c;
border-right:1px solid #56493c
}
.roundfg {
background:#645546
}
JavaScript:使用 jQuery 1.3.2 库。
$(document).ready(function(){
$("#main-nav li a.main-link").hover(function(){
$("#main-nav li a.main-link").removeClass("active");
$(this).addClass("active");
$("#sub-link-bar").animate({
height: "40px"
});
$(".sub-links").hide();
$(this).siblings(".sub-links").fadeIn();
});
$("#main-nav").mouseleave(function(){
$("#main-nav li a.main-link").removeClass("active");
$(".sub-links").fadeOut();
$("#sub-link-bar").animate({
height: "1px"
});
});
});
HTML:
</head>
<body>
<ul id="main-nav">
<li><a class="main-link active" href="">Home</a></li>
<li><a class="main-link subLink" href="">Tutorials</a>
<ul class="sub-links" style="display: none;">
<li><a href="" title="">Design</a> </li>
<li><a href="" title="">HTML & CSS</a> </li>
<li><a href="" title="">Other</a> </li>
<li><a href="" title="">PHP</a> </li>
<li><a href="" title="">Ruby</a> </li>
<li><a href="" title="">Site Builds</a> </li>
<li><a href="" title="">Tools & Tips</a> </li>
<li class="cat-item cat-item-35"><a href="" title="">Wordpress</a> </li>
</ul>
</li>
<li><a class="main-link subLink" href="">Articles</a>
<ul class="sub-links" style="display: none;">
<li><a href="" title="">General</a> </li>
<li><a href="" title="">Interviews</a> </li>
<li><a href="" title="">News</a> </li>
<li><a href="" title="">Web Roundups</a> </li>
</ul>
</li>
<li><a class="main-link subLink" href="">Freebies</a>
<ul class="sub-links" style="display: none;">
<li><a href="" title="">Books</a> </li>
<li><a href="" title="">Icons</a> </li>
<li><a href="" title="">Lightboxes</a> </li>
<li><a href="" title="">Others</a> </li>
<li><a href="" title="">Plugins</a> </li>
<li><a href="" title="">Themes</a> </li>
<li><a href="" title="">Tooltips</a> </li>
</ul>
</li>
<li><a class="main-link subLink" href="">Videos</a>
<ul class="sub-links" style="display: none;">
<li><a href="" title="">Screencasts</a></li>
</ul>
</li>
<li><a class="main-link" href="">Contact</a></li>
</ul>
</div>
<div id="sub-link-bar"></div>