美文网首页
滑动开关

滑动开关

作者: goodluckall | 来源:发表于2019-07-30 15:25 被阅读0次
    1.用 bootstrap中的switch控件
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title>bootstrap</title>
        <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
        <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap-switch/3.3.4/css/bootstrap3/bootstrap-switch.min.css" rel="stylesheet">
    </head>
    <body>
        <input type="checkbox" name="checkbox1" checked>
        <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
        <script src="https://cdn.bootcss.com/bootstrap-switch/3.3.4/js/bootstrap-switch.min.js"></script>
        <script>
            $(document).ready(function(){
                $("[name='checkbox1']").bootstrapSwitch();
            })
        </script>
    </body>
    </html>
    
    2.自定义(html+css)(兼容性只测了谷歌和360)
    <!DOCTYPE html>
    <html>
    <head>
        <title>滑动开关</title>
        <style type="text/css">
            .onoffswitch {
                position: relative; 
                width: 110px;
                -webkit-user-select:none;
                -moz-user-select:none; 
                -ms-user-select: none;
            }
            .onoffswitch-checkbox {
                display: none;
            }
            .onoffswitch-label {
                display: block; 
                overflow: hidden; 
                cursor: pointer;
                border: 2px solid #E3E3E3; 
                border-radius: 36px;
            }
            .onoffswitch-inner {
                display: block; 
                width: 200%; 
                margin-left: -100%;
                transition: margin 0.3s ease-in 0s;
            }
            .onoffswitch-inner:before, .onoffswitch-inner:after {
                display: block; 
                float: left; 
                width: 50%; 
                height: 36px; 
                padding: 0; 
                line-height: 36px;
                font-size: 16px; 
                color: white; 
                font-family: Trebuchet, Arial, sans-serif; 
                font-weight: bold;
                box-sizing: border-box;
            }
            .onoffswitch-inner:before {
                    content: "on";
                    padding-left: 10px;
                    background-color: #FFFFFF;
                    color: #27A1CA;
                    text-align: left;
            }
            .onoffswitch-inner:after {
                content: "off";
                padding-right: 10px;
                background-color: #FFFFFF; 
                color: #666666;
                text-align: right;
            }
            .onoffswitch-switch {
                display: block; 
                width: 36px; 
                margin: 0px;
                background: #A1A1A1;
                position: absolute; 
                top: 0; bottom: 0;
                right: 70px;
                border: 2px solid #E3E3E3; 
                border-radius: 36px;
                transition: all 0.3s ease-in 0s; 
            }
            .onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
                margin-left: 0;
            }
            .onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
                right: 0px; 
                background-color: #27A1CA; 
            }
        </style>
    </head>
    <body>
    <div class="onoffswitch">
        <!-- 开关默认关闭 -->
        <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch">
        <label class="onoffswitch-label" for="myonoffswitch">
            <span class="onoffswitch-inner"></span>
            <span class="onoffswitch-switch"></span>
        </label>
    </div>
    </body>
    </html>
    

    相关文章

      网友评论

          本文标题:滑动开关

          本文链接:https://www.haomeiwen.com/subject/jtjnrctx.html