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>
<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>
相关文章推荐
- jquery动态导航三
- jquery--动态导航二
- jquery--动态导航
- jquery--图片轮番效果
- jquery中如实现判断复选框是否选中,获取选中单选按钮的值,获取选中复选框的值
- jQuery validate 动态添加校验
- JS、Jquery实现---把后台传过来的时间毫秒数转换成想要的日期格式
- jQuery验证控件jquery.validate.js使用说明+中文API
- JSON.parse(),JSON.stringify(),jQuery.parseJSON()的用法
- IE8下Jquery获取select选中的值的问题
- jquery取某id的值
- jQuery学习日记(一):jQuery 对象与 DOM 对象
- jquery选择器最后一个,倒数第二个元素
- jquery添加插入元素
- DIV 拖拽
- Jquery $.extend的重载方法详述
- jQuery MiniUI - 专业WebUI控件库。
- jquery中children()与find()用法区别详解
- 160620、利用 jQuery UI 和 Ajax 创建可定制的 Web 界面
- 160616、jQuery插件之ajaxFileUpload及jqueryeasyui学习资料分享