diff --git a/src/components/ThemeToggle.astro b/src/components/ThemeToggle.astro index 37012dd..67107ab 100644 --- a/src/components/ThemeToggle.astro +++ b/src/components/ThemeToggle.astro @@ -1,41 +1,46 @@ function initTheme() { const theme = (() => { - // 1. 检查 localStorage if (typeof localStorage !== 'undefined' && localStorage.getItem('theme')) { return localStorage.getItem('theme') } - // 2. 检查系统主题 if (window.matchMedia('(prefers-color-scheme: dark)').matches) { return 'dark' } - // 3. 使用默认主题 return defaultMode })() - document.documentElement.classList.toggle('dark', theme === 'dark') } -// 立即执行初始化 initTheme() -// 监听系统主题变化 window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => { - if (!localStorage.getItem('theme')) { // 只在用户未手动设置主题时响应 + if (!localStorage.getItem('theme')) { document.documentElement.classList.toggle('dark', e.matches) } }) diff --git a/src/styles/global.css b/src/styles/global.css index d28117a..5c26414 100644 --- a/src/styles/global.css +++ b/src/styles/global.css @@ -64,7 +64,7 @@ animation: none; z-index: -1; } @supports not (view-transition-name: none) { - body { + body:not([data-restore-theme]) { --at-apply: 'transition-all duration-500 ease-in-out'; } - } \ No newline at end of file +} \ No newline at end of file diff --git a/src/styles/scrollbar.css b/src/styles/scrollbar.css index 2d0b09d..7388ecd 100644 --- a/src/styles/scrollbar.css +++ b/src/styles/scrollbar.css @@ -12,9 +12,9 @@ } .scrollbar-light { - --os-handle-bg: #D1C6BE; - --os-handle-bg-hover: #C1B6AF; - --os-handle-bg-active: #C1B6AF; + --os-handle-bg: #C9C4C1; + --os-handle-bg-hover: #B8B3B0; + --os-handle-bg-active: #B8B3B0; } .scrollbar-dark {