以下是 jQuery鼠标经过二级菜单渐隐效果js代码 的示例演示效果:
部分效果截图:
HTML代码(index.html):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery鼠标经过二级菜单渐隐效果</title>
<style type="text/css">
*{margin:0;padding:0;list-style:none;}
img{border:0;}
body{padding-top:100px;}
/* navbox */
.navbox ul{width:800px;overflow:hidden;height:auto;position:absolute;left:50%;top:0;margin-left:-400px;z-index:30;}
.navbox ul li{width:100px;height:auto;overflow:hidden;float:left;text-align:center; position:relative;z-index:-1;}
.navbox ul li a{width:100%;height:100px;line-height:100px;display:block;float:left;font-size:14px;font-family:'微软雅黑';color:#666;text-decoration:none;display:block;}
.navbox ul li a.first{background:none;}
.navbox ul li.on a{color:#fff;}
.navbox ul li .second{width:70px;height:130px;padding:10px;float:left;background:#f6f6f6;display:none;margin-left:5px;}
.navbox .dot{width:800px;height:8px;line-height:8px;position:absolute;left:50%;top:70px;margin-left:-395px;z-index:90000;}
.navbox .dot ul{width:800px;height:8px;line-height:8px;position:relative;}
.navbox .dot ul span{width:90px;height:8px;background:url(dot.png) no-repeat center center;display:block;position:absolute;left:0;top:0;z-index:999;}
.navbox .dot_a{width:800px;height:100px;line-height:100px;position:absolute;left:50%;top:0px;margin-left:-395px;z-index:-1;}
.navbox .dot_a ul{width:800px;height:100px;line-height:100px;position:relative;}
.navbox .dot_a ul span{width:90px;height:100px;background:#0b89ea;display:block;position:absolute;left:0;top:0;z-index:-1;}
</style>
</head>
<body>
<div class="navbox">
<ul>
<li class="on"><a href="#" class="first">网站首页</a><div class="second">1</div></li>
<li><a href="#">客户案例</a><div class="second">2</div></li>
<li><a href="#">服务项目</a><div class="second">3</div></li>
<li><a href="#">关于我们</a><div class="second">4</div></li>
<li><a href="#">新闻资讯</a><div class="second">5</div></li>
<li><a href="#">联系我们</a><div class="second">6</div></li>
<li><a href="#">分支机构</a><div class="second">7</div></li>
</ul>
<div class="dot_a"><ul><span></span></ul></div>
<div class="dot"><ul><span></span></ul></div>
</div>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(function(){
var liWidth = $('.navbox ul li').width();
$('.navbox ul li').hover(function(){
var index = $(this).index();
$('.navbox .dot span').stop().animate({left:liWidth*index+'px'},200);
$('.navbox .dot_a span').stop().animate({left:liWidth*index+'px'},200);
$(this).addClass('on').siblings().removeClass('on');
$(this).find('.second').fadeIn(600);
},function(){
$(this).find('.second').fadeOut(600);
});
});
</script>
</body>
</html>