您的位置:首页 > Web前端 > JQuery

jquery的下拉选择框

2016-06-29 16:10 375 查看
html代码:

<body>
<div class="select">
<p data-value="所以选项">用户中心</p>
<ul>
<li data-value="个人资料" >个人资料</li>
<li data-value="密码修改">密码修改</li>
<li data-value="我的订单">我的订单</li>
<li data-value="退出">退出</li>
</ul>
</div>
</body>

css代码:

<style>
.select{
width: 120px;
height: 40px;
background: #ff8;
margin: 0px auto;
position: relative;
cursor: pointer;
}
.select::after{
content: "";
display: block;
width: 10px;
height: 10px;
border-left: 1px solid #D0D0D0;
border-bottom: 1px solid #D0D0D0;
top: 12px;
right: 12px;
position: absolute;
transform: rotate(-46deg);
transition: all .3s ease-in;
}
.select p{
width: 120px;
line-height: 40px;
font-size: 16px;
font-family: "microsoft yahei";
color: #666666;
padding: 0px 15px;
}
.select ul{
width: 100px;
display: block;
font-size: 16px;
background: #FFFFFF;
position: absolute;
top: 40px;
left: 0px;
max-height: 0px;
overflow: hidden;
transition: max-height .3s ease-in;
}
.select ul li{
width: 100%;
height: 30px;
line-height: 30px;
padding: 0px 15px;
list-style: none;
color: #666666;
}
.select ul li.Selected{
background: yellowgreen;
color: #FFFFFF;
}
.select ul li:hover{
background: #D0D0D0;
}
@-webkit-keyframes slide-down{
0%{transform: scale(1,0);}
25%{transform: scale(1,1.2);}
50%{transform: scale(1,0.85);}
75%{transform: scale(1,1.05);}
100%{transform: scale(1,1);}
}

.select.open ul{
max-height: 250px;
transform-origin: 50% 0;
-webkit-animation: slide-down .5s ease-in;
transition: max-height .2s ease-in;
}
.select.open::after{
transform: rotate(134deg);
transition: all .3s ease-in;
top: 18px;

}
</style>

js代码:

<script>
$(function(){
$(".select p").click(function(e){
$(".select").toggleClass('open');
e.stopPropagation();
});

$(".content .select ul li").click(function(e){
var _this=$(this);
$(".select > p").text(_this.attr('data-value'));
_this.addClass("Selected").siblings().removeClass("Selected");
$(".select").removeClass("open");
e.stopPropagation();
});

$(document).on('click',function(){
$(".select").removeClass("open");
})

});
</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: