改进了网上其他导航的缺点,比如多次鼠标滑过后动画会重复播放多次。本例使用了stop()函数,使鼠标移出之后动画自动停止,而且不会出现重复动画现象
代码如下:nav.js
$(document).ready(function(){ $("ul.nav li a").parent().hover(function(){ $(this).find("ul.nav_child").stop(false, true).slideDown('slow').show(); }, function(){ $(this).find("ul.nav_child").stop(false, true).slideUp('slow'); }); });
base.css:
body{ /*background:#FF9D3C; */ font-size:12px; font-family:"宋体",Verdana, Arial; line-height:150%; padding:0; margin:0; color:#2F2F2F; text-align: center; } div{ margin:0 auto; padding:0; } a{ text-decoration:none; color:#2F2F2F; } a:hover{ text-decoration:underline; } h1{ text-align: center; } .nav_div{ width: 100%; height: 50px; background-color: #07861B; } .nav{ width: 1000px; height: 50px; line-height: 50px; margin: 0 auto; margin-bottom: 5px; list-style-type:none; } .nav li{ float:left; position: relative; } .nav li a{ padding:10px 22px; font-family: "微软雅黑"; color: white; font-weight: bold; font-size: 19px; } .nav li a:hover{ background-color: #22c108; text-decoration: none; color: white; } .nav li.selected a{ background-color: white; } .nav_child{ list-style-type:none; width: 150px; position: absolute; /*--Important - Keeps subnav from affecting main navigation flow--*/ left: 0; top: 45px; background: #07861B; margin: 0; padding: 0; display: none; float: left; border: 1px solid #111; font-size: 12px; } .nav_child li{ width: 100%; height: 40px; line-height: 40px; margin: 0; padding: 0; border-top: 1px solid #252525; /*--Create bevel effect--*/ border-bottom: 1px solid #444; /*--Create bevel effect--*/ clear: both; } .nav_child li a{ font-size: 12px; }