Fix dark light mode flicker

This commit is contained in:
Nicky van Urk
2020-09-14 18:42:29 +02:00
parent fefff75774
commit 484d30b622
6 changed files with 94 additions and 19 deletions

View File

@@ -2,17 +2,6 @@
// Theme switch
const body = document.body;
const lamp = document.getElementById("mode");
const data = body.getAttribute("data-theme");
const initTheme = (state) => {
if (state === "dark") {
body.setAttribute("data-theme", "dark");
} else if (state === "light") {
body.removeAttribute("data-theme");
} else {
localStorage.setItem("theme", data);
}
};
const toggleTheme = (state) => {
if (state === "dark") {
@@ -26,8 +15,6 @@
}
};
initTheme(localStorage.getItem("theme"));
lamp.addEventListener("click", () =>
toggleTheme(localStorage.getItem("theme"))
);