mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-16 19:51:07 +02:00
fix: theme toggle error
This commit is contained in:
parent
a8c56b6e8a
commit
8962f2613d
1 changed files with 8 additions and 0 deletions
|
@ -20,7 +20,15 @@
|
||||||
document.startViewTransition(switchTheme)
|
document.startViewTransition(switchTheme)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Synchronize theme status
|
||||||
|
function syncTheme() {
|
||||||
|
const theme = localStorage.getItem('theme')
|
||||||
|
document.documentElement.classList.toggle('dark', theme === 'dark')
|
||||||
|
themeToggle.setAttribute('aria-pressed', String(theme === 'dark'))
|
||||||
|
}
|
||||||
|
|
||||||
themeToggle.addEventListener('click', toggleTheme)
|
themeToggle.addEventListener('click', toggleTheme)
|
||||||
|
document.addEventListener('astro:after-swap', syncTheme)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue