mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 07:33:07 +08:00
Add light/dark mode functionality
This commit is contained in:
@@ -59,3 +59,18 @@
|
||||
@apply w-6 h-6 fill-skin-base hover:fill-skin-accent;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
const themeBtn = document.querySelector("#theme-btn");
|
||||
const htmlClassList = document.querySelector("html")?.classList;
|
||||
|
||||
themeBtn?.addEventListener("click", function () {
|
||||
if (htmlClassList?.contains("theme-dark")) {
|
||||
localStorage.setItem("theme", "light");
|
||||
htmlClassList?.remove("theme-dark");
|
||||
} else {
|
||||
localStorage.setItem("theme", "dark");
|
||||
htmlClassList?.add("theme-dark");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user