Skip to content

Commit 6e7ea36

Browse files
author
Pierre Galvez
committed
Fix #46 : Dark mode flickers on load of new page
For this, I moved the theme attribute from body to the html tag
1 parent a96aab8 commit 6e7ea36

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

sass/deep-thought.sass

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ $family-sans-serif: "Jost", sans-serif;
88
$footer-padding: 1.0rem 2.5rem;
99

1010
@mixin base_dark
11-
filter: invert(1) hue-rotate(180deg);
12-
11+
body,
1312
img,
1413
picture,
1514
video,
@@ -26,11 +25,11 @@ body
2625
min-height: 100vh;
2726

2827

29-
body[theme="dark"]
28+
html[theme="dark"]
3029
@include base_dark()
3130

3231

33-
body[theme="auto"]
32+
html[theme="auto"]
3433
@media (prefers-color-scheme: dark)
3534
@include base_dark()
3635

static/js/site.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function search() {
171171
}
172172

173173
function setTheme(color) {
174-
document.body.setAttribute("theme", color);
174+
document.documentElement.setAttribute("theme", color);
175175
document.getElementById("dark-mode").setAttribute("title", "Switch to "+color+" theme");
176176
}
177177

@@ -219,7 +219,7 @@ function documentReadyCallback() {
219219
});
220220

221221
document.getElementById("dark-mode").addEventListener("click", () => {
222-
const theme = document.body.getAttribute("theme");
222+
const theme = document.documentElement.getAttribute("theme");
223223
const isDarkMode = window.matchMedia("(prefers-color-scheme: dark)").matches;
224224
if (
225225
theme === "light" || theme === null || (theme === "auto" && !isDarkMode)

0 commit comments

Comments
 (0)