jquery实现下拉菜单
效果:
代码:
*{margin: 0px;padding: 0px}
.nav{background-color: #eee;width: 600px;height: 40px;margin: 0 auto;}
.nav-ul{list-style: none;}
.nav-ul li{float: left;line-height: 40px;text-align: center;position: relative;}
.nav-ul li a {text-decoration: none;color: #000;display: block;padding:0 10px;}
.nav-ul li a:hover{color: #FFF;background-color: #666}
.nav-ul li .nav-ul-li-ul{position: absolute;left: 0px; top:40px;display: none;}
.nav-ul li .nav-ul-li-ul li {list-style: none; float: none;background-color: #eee;margin-top: 2px;}
.nav-ul li .nav-ul-li-ul li a:hover{color: #FFF;background-color: #36e}
$(function () {
//鼠标悬浮到元素上
$(".nav-ul .nav-ul-li").mouseover(function(){
$(this).children(".nav-ul-li-ul").show();
});
//鼠标离开元素时
$(".nav-ul .nav-ul-li").mouseout(function(){
$(this).children(".nav-ul-li-ul").hide();
});
});