NavBar的jQuery悬停效果不起作用?

出于某种原因,我无法让悬停效果起作用
HTML

CSS:

#navbarcontainer {
margin: 0;
padding: 0;
height: 50px;
background: #01216D;
}

#navbarcontainer ul {
    clear: both;
    margin: 0;
    padding: 0;
    list-style: none;
}

#navbarcontainer li {
    display: inline-block;
    height: 50px;
    width: 100px;
    list-style: none;
    text-align: center;
    -moz-transition: .5s;
    -o-transition: .5s;
    -webkit-transition: .5s;
    transition: .5s;
    /* Firefox 4 */
    /* Opera */
    /* Safari and Chrome */
}

    #navbarcontainer ul li a {
        text-decoration: none;
        line-height: 50px;
        width: 100px;
        font-size: 20px;
        font-family: Calibri;
        cursor: pointer;
    }

#left {
    margin-right: 40px;
    margin-left: 20px;
}

#right {
    margin-left: 40px;
}

.current {
    background: #fff;
}

#current {
    color: #01216D;
font-weight: bold;
}

#dependant1,#dependant2 {
   color: #fff;
}

jQuery的:

$("#dependant1").hover(function () {
    $('.dependant1').stop().animate({background: '#fff' },"slow");
    $('#dependant1').stop().animate({color: '#01216D','font-weight': 'bold'},"slow");
},function () {
    $('.dependant1').stop().animate({ background: 'none' },"slow");
    $('#dependant1').stop().animate({color: '#fff','font-weight': 'normal'},"slow");
});

我觉得它与jQuery有关,但我在document.load中有它,所以我不明白为什么它不起作用.

最佳答案
你需要在jQuery之后包含jQuery UI库:

LIVE DEMO

$("#navbarcontainer li").hover(function () {
    $(this).find('a').stop().animate({ color: '#01216D',backgroundColor: '#fff'},800);
},function () {
    $(this).find('a').stop().animate({ color: '#fff',backgroundColor: '#01216D'},800);
 });

HTML:

 

CSS:

#navbarcontainer {
    margin: 0;
    padding: 0;
    background: #01216D;
}
#navbarcontainer ul {
    clear: both;
    margin: 0;
    padding: 0;
    list-style: none;
    overflow:hidden;
}
#navbarcontainer li {
    list-style: none;
    text-align: center;
    -moz-transition: .5s;
    -o-transition: .5s;
    -webkit-transition: .5s;
    transition: .5s;
}
#navbarcontainer ul li a {
    float:left;
    color:#fff;
    background: #01216D;
    padding:10px 30px;
    text-decoration: none;
    line-height: 50px;
    font-size: 20px;
    font-family: Calibri;
    cursor: pointer;
}
#current {
    background: #fff !important;
    color: #01216D !important;
    font-weight: bold;
}

或者另一个脚本:

$("#navbarcontainer li").on('mouseenter mouseleave',function ( e ) {
  var set = e.type=='mouseenter' ? {c:"#01216D",bg:"#fff"} : {c:"#fff",bg:"#01216D"} ;
  $('a',this).stop().animate({ color: set.c,backgroundColor: set.bg},800);
});

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...