Created
January 17, 2021 08:06
-
-
Save infantiablue/a212fd672f95368e7e57db8b3368166e to your computer and use it in GitHub Desktop.
Hnews Toggle Darkmode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
toggleDarkMode(theme, evt) { | |
let htmlElm = document.querySelector("html"); | |
const setLight = () => { | |
htmlElm.classList.remove("dark"); | |
localStorage.theme = "light"; | |
this.$refs.toggleDark.textContent = "☀️"; | |
}; | |
const setDark = () => { | |
htmlElm.classList.add("dark"); | |
localStorage.theme = "dark"; | |
this.$refs.toggleDark.textContent = "🌙"; | |
}; | |
if (typeof theme === "string") { | |
if (theme == "dark") setDark(); | |
else setLight(); | |
} else { | |
if (localStorage.theme === "dark") setLight(); | |
else setDark(); | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment