做一个好看的checkbox

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

在这里插入图片描述
![在这里插入图片描述](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>

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值