- 彤彤杰作
需要做一个类似select的下拉 但是样式有改变 option的hover样式谷歌浏览器不能更改,所以自定义
后期由于需要在页面任意地方点击能够关闭弹框,所以添加了遮罩层
下拉框模拟 select中option的背景色改变
.this_select_style{
display:inline-block;
position:relative;
}
.this_select_style input{
width:260px;
/*padding: 5px 50px 5px 20px;*/
padding-left:5px;
height: 35px;
border: 1px solid #d8d8d8;
box-sizing: border-box;
border-radius: 5px;
color: #999;
background: url(../images/Mall_select.png) no-repeat 87% 54%;
}
.this_select_style ul{
width:260px;
border: 1px solid #d8d8d8;
border-top:none;
border-radius: 0 0 5px 5px;
color: #999;
padding:0;
position:absolute;
top:19px;
background-color:#fff;
z-index:9999;
display:none;
box-sizing: border-box;
}
.this_select_style .show_ul{
border-radius:5px 5px 0 0;
border-bottom:none;
background:none;
}
.this_select_style ul li{
width:100%;
padding: 5px 50px 5px 20px;
cursor:pointer;
box-sizing: border-box;
}
.this_select_style ul li:hover{
color:#fff;
background-color:#1bbc9b;
}
#mask{
width: 100vw;
height: 100vh;
background: rgba(0,0,0,0);//为了测试,可以加上背景色
position: fixed;
left: 0;
top:0;
z-index: 999;
display: none;
}
<div id="mask"></div>
<div class="this_select_style">
<input type="text" readonly="true" class="selectmenu" style="background-color: #fff;" data-value="-1" value="等待发货收货"/>
<ul>
<li data-value="0">全部</li>
<li data-value="1">待审核</li>
<li data-value="1">已拒绝</li>
<li data-value="1">等待发货收货</li>
<li data-value="1">订单取消</li>
<li data-value="1">交易结束</li>
</ul>
</div>
//下拉框
$('body').on('click', '.this_select_style .selectmenu', function () {
$this = $(this);
$this.toggleClass("show_ul");
$this.next().toggle();
$('#mask').show();
});
$('body').on('click', '.this_select_style li', function () {
$this = $(this);
var thisInput = $this.parent().siblings("input");
thisInput.attr("data-value", $this.attr("data-value")).val($this.text()).toggleClass("show_ul");
$this.parent().hide();
$('#mask').hide();
})
$('body').on('click', function (e) {
if(!$(e.target).hasClass('selectmenu'))
{
$('#mask').hide();
$('.this_select_style .selectmenu').removeClass("show_ul");
$('.this_select_style ul').hide();
}
})
我叫洱月,我愿意陪你到洱海风花雪月,你,看到我了吗?
网友评论