好的,所以我一直在尝试在我的网站上实现暗模式功能。我制作了一个显示在页面右下方的小部件。我将整个网站包含在一个名为test的div中。单击窗口小部件后,它将切换并将dark-mode-screen
类添加到test
div中。
但是,只有文本和窗口小部件的颜色发生变化,而背景保持不变。
CSS
.box {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border: 1px solid #333;
padding: 10px 20px;
font-family: sans-serif;
mix-blend-mode: normal;
transition: mix-blend-mode 0.7s ease-in;
}
.dark-button {
position: absolute;
right: 20px;
bottom: 20px;
border-radius: 50px;
height: 60px;
width: 60px;
border: 1px solid steelblue;
background: steelblue;
outline: none;
}
.dark-mode-screen {
width: 100vw;
height: 100%;
position: fixed;
top: 0;
left: 0;
background: white;
overflow-y: scroll;
}
.test {
background: #fff;
transition: all 0.7s ease-in;
}
HTML:
<div class="test">
<div class="container" style="background: #fff; mix-blend-mode: difference;">
<div class="box">
<h3>My Paragraph</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<button class="dark-button"></button>
</div>
</div>
JavaScript:
const darkModeToggle = document.querySelector('.dark-button');
darkModeToggle.onclick = function() {
document.querySelector('.test').classList.toggle('dark-mode-screen');
}
答案 0 :(得分:0)
您可以将background-color
CSS属性设置为白色mix-blend-mode
,但其中没有任何要减去的内容:
.box {
...
background-color: white;
}
const darkModeToggle = document.querySelector('.dark-button');
darkModeToggle.onclick = function() {
document.querySelector('.test').classList.toggle('dark-mode-screen');
}
.box {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border: 1px solid #333;
padding: 10px 20px;
font-family: sans-serif;
mix-blend-mode: normal;
transition: mix-blend-mode 0.7s ease-in;
background-color: white;
}
.dark-button {
position: absolute;
right: 20px;
bottom: 20px;
border-radius: 50px;
height: 60px;
width: 60px;
border: 1px solid steelblue;
background: steelblue;
outline: none;
}
.dark-mode-screen {
width: 100vw;
height: 100%;
position: fixed;
top: 0;
left: 0;
background: white;
overflow-y: scroll;
}
.test {
background: #fff;
transition: all 0.7s ease-in;
}
<div class="test">
<div class="container" style="background: #fff; mix-blend-mode: difference;">
<div class="box">
<h3>My Paragraph</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<button class="dark-button"></button>
</div>
</div>