下拉框样式

html:

<div class="content">
                        <span>单位名称:</span>
                        <div class="select">
                            <p data-value="-1">请选择</p>
                            <ul class="all-animate">
                                <li data-value="单位#1">单位#1</li>
                                <li data-value="单位#2">单位#2</li>
                                
                            </ul>
                        </div>
                    </div>

css:

/**
 * 下拉列表*/
.content{
    width: 22%;
    display: inline-block;
    margin-bottom: 1rem;
}
.content>span{
    width: 50%;
}
.content .select{
    display: inline-block;
    width: 50%; 
    height: 3rem; 
    line-height: 3rem;
    background: #FFFFFF; 
    position: relative;
    cursor: pointer;
    border: 1px solid #dcdcdc;
    border-radius: 0.5rem;
}
.content .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;
}
.content .select p{
    width: 80%;
    line-height: 3rem; 
    font-size: 1.2rem;
    font-family: "microsoft yahei";
    color: #666666;
    padding: 0px 15px;
}
.content .select ul{
    border: 1px solid #dcdcdc;
    border-radius: 0.5rem;
    width: 100%;
    display: none;
    font-size: 1.2rem;
    background: #FFFFFF;
    position: absolute;
    top: 3rem;
    left: 0px;
    max-height: 0px;
    overflow: hidden;
    z-index: 999;
    transition: max-height .3s ease-in;
}
.content .select ul li{
    width: 100%;
    height: 3rem;
    line-height: 3rem;
    padding: 0px 15px;
    list-style: none;
    color: #666666;
}
.content .select ul li.Selected{
    background: #FF8000;
    color: #FFFFFF;
}
.content .select ul li:hover{
    background: #FF8000;
    color: #FFFFFF;
}
@-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);}
}

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

js:

/**
 * 下拉列表*/

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

转载于:https://my.oschina.net/lslDn/blog/1538102

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值