【发布时间】:2012-06-15 03:34:35
【问题描述】:
我希望有人可以帮助我。我有以下问题:
标记:
<nav>
<ul id="topNav">
<li id="topNavFirst"><a href="pages/about/about.php" id="aboutNav">About Us</a></li>
<li id="topNavSecond"><a href="pages/people/our-people.php" id="peopleNav">Our People</a>
<ul id="subList1">
<li><a href="pages/people/mike-hadfield.php">Mike Hadfield</a></li>
<li><a href="pages/people/karen-sampson.php">Karen Sampson</a></li>
<li><a href="pages/people/milhana-farook.php">Milhana Farook</a></li>
<li><a href="pages/people/kim-crook.php">Kim Crook</a></li>
<li><a href="pages/people/amanda-lynch.php">Amanda Lynch</a></li>
<li><a href="pages/people/gideon-scott.php">Gideon Scott</a></li>
<li><a href="pages/people/paul-fuller.php">Paul Fuller</a></li>
<li><a href="pages/people/peter-chaplain.php">Peter Chaplain</a></li>
<li><a href="pages/people/laura-hutley.php">Laura Hutley</a></li>
</ul>
</li>
<li id="serviceNavDropdown"><a href="our-services.php" id="servicesNav">Our Services</a>
<ul id="subList2">
<li><a href="pages/services/company-and-commercial.php">Company & Commercial</a></li>
<li><a href="pages/services/employment.php">Employment</a></li>
<li><a href="pages/services/civil-litigation.php">Civil Litigation</a></li>
<li><a href="pages/services/debt-recovery.php">Debt Recovery</a></li>
<li><a href="pages/services/conveyancing.php">Conveyancing</a></li>
<li><a href="pages/services/commercial-property.php">Commerical Property</a></li>
<li><a href="pages/services/wills-and-probate.php">Wills & Probate</a></li>
<li><a href="pages/services/family.php">Matrimonial & Family</a></li>
</ul>
</li>
<li><a href="pages/news/news.php" id="newsNav">News</a></li>
<li><a href="pages/careers/careers.php" id="careersNav">Careers</a></li>
<li><a href="pages/contact/contact.php" id="contactNav">Contact</a></li>
</ul><!-- /topNav -->
</nav>
CSS
#topNav {
float:right;
height:30px;
margin:0;
font-size:12px;
}
#topNav li {
display:inline;
list-style:none;
color:#666;
border-left: 1px solid #666;
padding: 0 0 0 3px;
}
#topNav li a:hover {
}
#topNavFirst {
border-left: 1px solid transparent !important;
}
#topNav ul{
background:#fff url(images/people-ul-bg.png) no-repeat;
border:1px solid #666;
border-top:0px solid transparent;
border-bottom:2px solid #666;
list-style:none;
position:absolute;
left:-9999px;
width:90px;
text-align:left;
padding:5px 0 5px 0px;
z-index:10;
}
#topNav ul li{
display:block;
border-left:0px;
margin-bottom: 0px;
padding:0;
}
#topNav ul a{
padding:0 0 0 5px;
}
#topNav li:hover ul{
left:auto;
margin-left:55px;
margin-top:-1px;
}
#topNav li:hover a {
color:#369;
}
#topNav li:hover ul a{
text-decoration:none;
color:#666;
}
#topNav li:hover ul li a:hover{
color:#fff;;
width:100%;
}
#topNav ul li:hover {
background:#369;
display: block;
}
#topNav ul li a {
display: block;
padding:0 0 0 4px;
}
#serviceNavDropdown ul{
background:#fff url(images/service-ul-bg.png) no-repeat;
width:135px !important;
margin-left:117px !important;
margin-top:-1px;
}
jQuery
jQuery(document).ready(function () {
$('#subList1').css("display", "none");
$('#topNavSecond').hover(function () {
$('#subList1').fadeIn('slow');
},
function(){
$('#subList1').fadeOut('slow');
});
$('#subList2').css("display", "none");
$('#serviceNavDropdown').hover(function () {
$('#subList2').fadeIn('slow');
},
function(){
$('#subList2').fadeOut('slow');
});
});
当 #topNavSecond ('Our People') 锚点悬停时,ul #subList1 应该淡入。现在,正如您从小提琴中看到的那样,它不会在第一次悬停时消失,而只会在后续悬停时消失。同样,下一个锚点(“我们的服务”)也在做同样的事情,并且在它们之间移动时存在一些褪色问题。
我已经达到了我对 jquery 知识的极限(诚然,这并不多!)并且非常感谢一些帮助。
编辑> 上面的代码是更正后的代码,并且正在运行。但是下面的jQuery更好,加了一些.stop(true, true):
jQuery(document).ready(function () {
$('#subList1').css("display", "none");
$('#topNavSecond').hover(function () {
$('#subList1').stop(true, true).fadeIn('slow');
},
function(){
$('#subList1').stop(true, true).fadeOut('slow');
});
$('#subList2').css("display", "none");
$('#serviceNavDropdown').hover(function () {
$('#subList2').stop(true, true).fadeIn('slow');
},
function(){
$('#subList2').stop(true, true).fadeOut('slow');
});
});
【问题讨论】:
-
jsFiddle 是这个网站上的一个很棒的工具,但您还需要让您的问题更加“独立”。否则,当jsFiddle站点宕机时,这个问题就没用了。
-
真的很抱歉 Sparky,我会在操作中包含代码。
标签: jquery css menu css-position