我希望有人可以帮助我。我有以下问题:

http://jsfiddle.net/zhPAF/

加价:

<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 &amp; 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 &amp; Probate</a></li>
                            <li><a href="pages/services/family.php">Matrimonial &amp; 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(“我们的人民”)锚点悬停时,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');
        });
    });

最佳答案

您已将其设置为$('#topNavSecond').parent().hover(function () #topNavSecond的父级将是整个UL。我相信你的意思是$('#topNavSecond').hover(function ()

看到这里:http://jsfiddle.net/zhPAF/1/

10-04 16:15