fix: lightswitch
This commit is contained in:
parent
0165c126a9
commit
73c3805fdb
1 changed files with 8 additions and 3 deletions
|
@ -159,8 +159,8 @@
|
||||||
</article>
|
</article>
|
||||||
<script>
|
<script>
|
||||||
function toggle() {
|
function toggle() {
|
||||||
document.body.classList.add('animation-ready');
|
const isCurrentlyDark = document.body.classList.contains('dark');
|
||||||
document.body.classList.toggle('dark');
|
applyTheme(!isCurrentlyDark);
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('keydown', function(event) {
|
document.addEventListener('keydown', function(event) {
|
||||||
|
@ -173,7 +173,12 @@
|
||||||
const btn = document.getElementById('lightswitch');
|
const btn = document.getElementById('lightswitch');
|
||||||
|
|
||||||
const applyTheme = isDark => {
|
const applyTheme = isDark => {
|
||||||
toggle();
|
document.body.classList.add('animation-ready');
|
||||||
|
if (isDark) {
|
||||||
|
document.body.classList.add('dark');
|
||||||
|
} else {
|
||||||
|
document.body.classList.remove('dark');
|
||||||
|
}
|
||||||
btn.textContent = isDark
|
btn.textContent = isDark
|
||||||
? '[lights on]'
|
? '[lights on]'
|
||||||
: '[lights out]';
|
: '[lights out]';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue