做一个好看的checkbox

废话啥啊,上代码吧
效果展示

做一个好看的checkbox_第1张图片
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200516205713297.gif#pic_center

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width,initial-scale=1">
        <title>checkbox</title>
        <style>
            *{
     
                margin: 0;
                padding: 0;
            }
            body{
     
                width: 100vw;
                height: 100vh;
                display: flex;
                justify-content: center;
                align-items: center;
            }
            .lz-checkbox {
     
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                margin: 0;
                padding: 0;
                color: rgba(0,0,0,.65);
                font-size: 14px;
                font-variant: tabular-nums;
                line-height: 1.5715;
                list-style: none;
                -webkit-font-feature-settings: 'tnum';
                font-feature-settings: 'tnum';
                position: relative;
                top: -.09em;
                display: inline-block;
                line-height: 1;
                white-space: nowrap;
                vertical-align: middle;
                outline: none;
                cursor: pointer;
            }
            .lz-checkbox-checked::after {
     
                position: absolute;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                border: 1px solid #1890ff;
                border-radius: 2px;
                visibility: hidden;
                -webkit-animation: antCheckboxEffect .36s ease-in-out;
                animation: antCheckboxEffect .36s ease-in-out;
                -webkit-animation-fill-mode: backwards;
                animation-fill-mode: backwards;
                content: '';
            }

            /* 第二个span */
            .lz-checkbox-checked .lz-checkbox-inner {
     
                background-color: #1890ff;
                border-color: #1890ff;
            }
            .lz-checkbox-inner {
     
                position: relative;
                top: 0;
                left: 0;
                display: block;
                width: 16px;
                height: 16px;
                direction: ltr;
                background-color: #fff;
                border: 1px solid #d9d9d9;
                border-radius: 2px;
                border-collapse: separate;
                -webkit-transition: all .3s;
                transition: all .3s;
            }
            .lz-checkbox-checked .lz-checkbox-inner::after {
     
                position: absolute;
                display: table;
                border: 2px solid #fff;
                border-top: 0;
                border-left: 0;
                -webkit-transform: rotate(45deg) scale(1) translate(-50%,-50%);
                transform: rotate(45deg) scale(1) translate(-50%,-50%);
                opacity: 1;
                -webkit-transition: all .2s cubic-bezier(.12,.4,.29,1.46) .1s;
                transition: all .2s cubic-bezier(.12,.4,.29,1.46) .1s;
                content: ' ';
            }
            .lz-checkbox-inner::after {
     
                position: absolute;
                top: 50%;
                left: 22%;
                display: table;
                width: 5.71428571px;
                height: 9.14285714px;
                border: 2px solid #fff;
                border-top: 0;
                border-left: 0;
                -webkit-transform: rotate(45deg) scale(0) translate(-50%,-50%);
                transform: rotate(45deg) scale(0) translate(-50%,-50%);
                opacity: 0;
                -webkit-transition: all .1s cubic-bezier(.71,-.46,.88,.6),opacity .1s;
                transition: all .1s cubic-bezier(.71,-.46,.88,.6),opacity .1s;
                content: ' ';
            }
            .lz-checkbox-inner:hover {
     
                border-color: #1890ff;
            }
        </style>
    </head>
    <body>
        <span id="span" class="">
            <span class="lz-checkbox-inner"></span>
        </span>
    </body>
    <script>
        let span = document.getElementById("span");
        span.className = "lz-checkbox"
        span.onclick = function() {
     
            span.className === "lz-checkbox"?
                span.className = "lz-checkbox lz-checkbox-checked"
                :span.className = "lz-checkbox"
        }
    </script>
</html>

你可能感兴趣的:(做一个好看的checkbox)