黑白主题切换
Pcjmy opened this issue · 2 comments
Pcjmy commented
黑白主题切换
morp-hex commented
<button>关灯</button>
<script>
var btn = document.querySelector('button');
var bd = document.querySelector('body');
btn.onclick = function () {
if (btn.innerHTML === '关灯') {
bd.style.backgroundColor = '#111';
btn.innerHTML = '开灯';
}
else {
bd.style.backgroundColor = '#fff';
btn.innerHTML = '关灯';
}
}
</script>
huccct commented
纯css版本
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.content {
width: 100%;
height: 600px;
transition: all 1s;
}
#modeCheckBox {
display: none;
}
#modeCheckBox:checked + .content {
background-color: black;
color: white;
transition: all 1s;
}
#modeBtn {
font-size: 2rem;
float: right;
}
#modeBtn::after {
content: '🌞';
}
#modeCheckBox:checked + .content #modeBtn::after {
content: '🌜';
}
</style>
</head>
<body>
<input id="modeCheckBox" type="checkbox" />
<div class="content">
<header>
<label id="modeBtn" for="modeCheckBox"></label>
</header>
</div>
</body>
</html>