html:
<div class="v-nav"> <ul style="position: relative;"> <li class="nav-li"> <p>首页</p> <p>首页</p> </li> <li class="nav-li"> <p>场景</p> <p>场景</p> </li> <li class="nav-li"> <p>模型</p> <p>模型</p> </li> <li class="nav-li"> <p>产品</p> <p>产品</p> </li> <li class="nav-li"> <p>我们</p> <p>我们</p> </li> <span class="nav_line"></span> </ul> </div>
css:
.v-nav{ width: 600px; height: 80px; line-height: 80px; color: #fff; font-family: "微软雅黑"; font-size: 16px; float: right; overflow: hidden; } .v-nav ul{ width: 100%; height: 100%; list-style-type: none; text-align: left; } .v-nav ul>li{ width: 120px; display: block; float: left; cursor: pointer; text-align: center; } .nav-li{ position: relative; } .nav-li:hover{ font-weight: bold; } .nav_line{ position: relative; top: 76px; left: 0px; height: 4px; width:120px; display: block; background: #fff; }
js(jQuery):
/*首页导航动画*/ $(function(){ $(".nav-li").mouseover(function(){ var nav_left = $(this).position().left;//元素当前的偏移 $(this).stop().animate({bottom:'80px'},300);//鼠标移至导航li上,文字上移 $(".nav_line").stop(true).animate({left:nav_left},300);//鼠标移至导航li时,下划线动画 }); $(".nav-li").mouseout(function(){ $(this).stop().animate({bottom:'0px'},300); $(".nav_li .nav_line").stop(true).animate({left:"0","0"},300); }); });