首页 » 收集 » 正文内容
不错的切换黑白主题动画特效
寻梦xunm| 749| 收集
3年前
超过1279天 温馨提示
本文最后更新于2021年05月22日,已超过1279天没有更新,若内容或图片失效,请留言反馈。

不错的切换黑白主题动画特效
火狐截图_2021-05-22T08-27-07.565Z.png
HTML代码:

<div class="toolbar-link" onclick="changeMode()">
    <label class="dark-mode ml-auto">
      <input type="checkbox" checked="false">
      <span></span>
    </label>
</div>

CSS样式:

 body {
    height:100vh;
    display:flex;
    align-items:center;
    justify-content:center;
    background:#f0f0f0;
    transition:all 0.3s;
}
body.is-dark {
    background:#3b3b41;
}
.toolbar-link {
    display:flex;
    justify-content:center;
    align-items:center;
    height:64px;
    width:64px;
    border-radius:9999px;
    margin:0 4px;
    transition:all .3s;
    border: 1px solid #ffb62e;
}
.toolbar-link:hover {
    background:#fff;
    border-color:#ededed;
    box-shadow:-1px 3px 10px 0 rgba(0,0,0,.06);
}
body.is-dark .toolbar-link:hover {
    background:#28282b;
}
.dark-mode {
    cursor:pointer;
    transform:translate3d(0,0,0);
    transform:scale(0.55);
}
.dark-mode input {
    display:none;
}
.dark-mode input+span {
    display:block;
    border-radius:9999px;
    width:36px;
    height:36px;
    position:relative;
    box-shadow:inset 16px -16px 0 0 #ffd22e;
    transform:scale(1) rotate(-2deg);
    transition:box-shadow .5s ease 0s,transform .4s ease .1s;
}
.dark-mode input+span::before {
    content:"";
    width:inherit;
    height:inherit;
    border-radius:inherit;
    position:absolute;
    left:0;
    top:0;
    backface-visibility:hidden;
    transition:background-color .3s ease;
}
.dark-mode input+span::after {
    content:"";
    width:8px;
    height:8px;
    border-radius:9999px;
    margin:-4px 0 0 -4px;
    position:absolute;
    top:50%;
    left:50%;
    box-shadow:0 -23px 0 #ffb62e,0 23px 0 #ffb62e,23px 0 0 #ffb62e,-23px 0 0 #ffb62e,15px 15px 0 #ffb62e,-15px 15px 0 #ffb62e,15px -15px 0 #ffb62e,-15px -15px 0 #ffb62e;
    transform:scale(0);
    transition:all .3s ease;
}
.dark-mode input:checked+span {
    box-shadow:inset 32px -32px 0 0 #ffd22e;
    transform:scale(.5) rotate(0);
    transition:transform .3s ease .1s,box-shadow .2s ease 0s;
}
.dark-mode input:checked+span::before {
    background:#ffb62e;
    backface-visibility:hidden;
    transition:background-color .3s ease .1s;
}
.dark-mode input:checked+span::after {
    transform:scale(1.5);
    transition:transform .5s ease .15s;
}

JS代码:

var check = document.getElementsByTagName('input')[0];

function changeMode() {
    if (check.checked) {
        document.getElementsByTagName('body')[0].className = '';
    } else {
        document.getElementsByTagName('body')[0].className = 'is-dark';
    }
}
0 赞 or 打赏
喜欢就打赏一点
微信 支付宝
20240430140454171445709417079.png
20240430140454171445709417079.png
隐私
Q Q:1340326824
邮箱:vipshiyi@qq.com
QQ群:422720328

我的音乐