started with basic content structure and header
This commit is contained in:
1 parent
9e7bc5c59c
commit
7ead3e64da
3 files changed
+188
-14
No files matched your search
@@ -0,0 +1,20 @@
|
||||
const themeButton = document.getElementById("theme-toggle");
|
||||
const root = document.documentElement;
|
||||
|
||||
themeButton.addEventListener("click", () => {
|
||||
const currentTheme = getCurrentTheme();
|
||||
|
||||
if (currentTheme === "light") {
|
||||
root.dataset.theme = "dark";
|
||||
return;
|
||||
}
|
||||
root.dataset.theme = "light";
|
||||
});
|
||||
|
||||
function getCurrentTheme() {
|
||||
const selectedTheme = root.dataset.theme;
|
||||
|
||||
if (selectedTheme !== undefined) return selectedTheme;
|
||||
if(window.matchMedia("(prefers-color-scheme: dark)").matches) return "dark";
|
||||
return "light";
|
||||
}
|
||||
Reference in new issue
Block a user