页面中常用平级下拉菜单(手风琴)
Jia2019-03-18 15:54:41292 demo.html:
<!DOCTYPE html>
<html lang="en">
<head>
<title>页面中常用平级下拉菜单(手风琴)</title>
<link rel="stylesheet" href="static/css/demo.css">
<link rel="stylesheet" href="static/font-awesome/css/font-awesome.min.css">
<link rel="shortcut icon" href="static/images/logo.png" type="image/x-icon">
<script src="static/js/jquery.js"></script>
</head>
<body>
<div class="nav">
<div class="parent">
<div class="one">
<strong>个人中心</strong>
</div>
<ul class="two">
<li><a href=""></a>我的信息</li>
<li><a href=""></a>系统通知</li>
<li><a href=""></a>短信息</li>
</ul>
</div>
<div class="parent">
<div class="one">
<strong>课程中心</strong>
</div>
<ul class="two">
<li><a href=""></a>我的信息</li>
<li><a href=""></a>系统通知</li>
<li><a href=""></a>短信息</li>
<ul>
</div>
<div class="parent">
<div class="one">
<strong>校内讨论</strong>
</div>
<ul class="two">
<li><a href=""></a>我的信息</li>
<li><a href=""></a>系统通知</li>
<li><a href=""></a>短信息</li>
</ul>
</div>
<div class="parent">
<div class="one">
<strong>资源中心</strong>
</div>
<ul class="two">
<li><a href=""></a>我的信息</li>
<li><a href=""></a>系统通知</li>
<li><a href=""></a>短信息</li>
</ul>
</div>
</div>
<script>
$(function(){
$('.two').css('display','none');
var one=$('.one');
var two=$('.two');
//each() 方法规定为每个匹配元素规定运行的函数。
$('.one').each(function(i){
$(this).click(function(){
if($(two[i]).css('display')=='none'){
$(two[i]).slideDown(400)
}else{
$(two[i]).slideUp(400)
};
});
});
});
</script>
</body>
</html>
demo.css:
*{
margin: 0px;
padding: 0px;
font-size: 14px;
font-family: "微软雅黑";
}
a{
text-decoration:none;
color: #36b2f5;
}
.nav{
width: 250px;
margin: 70px auto;
border-top: 4px solid #36b2f5;
border-bottom: 3px solid #36b2f5;
}
.nav .one{
border-bottom: 1px solid #36b2f5;
border-right: 1px solid #36b2f5;
border-left: 1px solid #36b2f5;
height: 40px;
line-height: 40px;
text-align: center;
cursor: pointer;
}
.two{
width: 248px;
border-right: 1px solid #36b2f5;
border-left: 1px solid #36b2f5;
}
.two li{
list-style: none;
height: 35px;
line-height: 35px;
text-align: center;
border-bottom: 1px dotted #36b2f5;
}