本文采用嵌套的ul、li代码实现二级导航菜单,并实现导航菜单栏的背景具有上下滑动的效果,注意此处鼠标悬停效果采用的是mouseenter和mouseleave,这对函数可以保证当鼠标在二级菜单移动时,导航菜单的背景不变化,如果采用mouseover和mouseout,鼠标在二级菜单移动一次,导航菜单背景就会上下滑动一次,用户体验差,大家可以自行修改代码观看效果,现将三部分代码贴入:
-----------------JQuery代码---------------------------
$(function(){
$(".navcon ul li").mouseenter(function(){
$(this).children("a").children(".out").stop(true,true).slideUp();
$(this).children("a").children(".over").stop(true,true).slideDown();
$(this).children("ul").show();
});
$(".navcon ul
li").mouseleave(function(){
$(this).children("a").children(".over").stop(true,true).slideUp();
$(this).children("a").children(".out").stop(true,true).slideDown();
$(this).children("ul").hide()
});
})
-----------------JQuery代码---------------------------
-----------------CSS样式---------------------------
div, ul, li, a,
span {
margin:0;
padding:0;
}
.nav .navcon ul {
height:40px;
width:100%;
}
.over {
background-color:#9F9;
}
.out {
background-color:#CFF;
}
.navcon ul li {
float:left;
width:100px;
height:40px;
list-style-type:none;
margin-left:3px;
line-height:40px;
text-align:center;
}
.navcon ul li a {
display:block;
width:100px;
height:40px;
overflow:hidden;
}
.navcon ul li a span {
display:block;
height:40px;
width:100px;
}
.navcon ul li ul {
display:none;
}
.navcon ul li ul li {
left:0;
}
-----------------CSS样式---------------------------
-----------------HTML代码---------------------------
-----------------HTML代码---------------------------