开关,自定义文字

html: 


        <div>
            <div class="on-off-off on-off">
                <span>off</span>
                <div class="kgYuan"></div>
            </div>
            <div class="on-off-on on-off isHide">
                <div class="kgYuan"></div>
                <span>on</span>
            </div>
        </div>

css样式:

.on-off {
    width: 50px !important;
    border: 1px solid #333;
    border-radius: 20px;
    display: flex;
    justify-content: space-between;
    line-height: 20px;
    margin-top: 12px;
    font-size: 12px;
}
.on-off-off {
    padding: 2px 2px 2px 10px;
    color: #fff;
    background: -webkit-linear-gradient(-90deg, #81afcf, #3a6c9e); /* Safari 5.1 - 6.0 */
    background: -o-linear-gradient(180deg, #81afcf, #3a6c9e); /* Opera 11.1 - 12.0 */
    background: -moz-linear-gradient(180deg, #81afcf, #3a6c9e); /* Firefox 3.6 - 15 */
    background: linear-gradient(180deg, #81afcf, #3a6c9e); /* 标准的语法 */
}
.on-off-on {
    background: #fff;
    padding: 2px 10px 2px 2px;
    color: #000 !important;
}
.kgYuan{
    width: 18px !important;
    height: 18px;
    background: #fff;
    border: 1px solid #333;
    border-radius: 14px;
    margin-top: 0 !important;
}
.isHide{
    display: none;
}

jquery:

$(".on-off").on('click',function(){
        if($(".on-off-off").hasClass("isHide")){
            $(".on-off-off").removeClass("isHide");
            $(".on-off-on").addClass("isHide");
        }else{
            $(".on-off-off").addClass("isHide");
            $(".on-off-on").removeClass("isHide");
        }


    });

样式: 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值