修复深色与浅色主题无法切换的问题
修正 CSS 选择器避免 :root 始终应用深色变量,并改进 theme.js 点击绑定与首屏主题恢复。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+15
-7
@@ -33,13 +33,21 @@
|
||||
apply(prefersLight ? 'light' : 'dark');
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
document.addEventListener('click', function (e) {
|
||||
var btn = e.target.closest('[data-theme-pick]');
|
||||
if (!btn) return;
|
||||
e.preventDefault();
|
||||
apply(btn.getAttribute('data-theme-pick'));
|
||||
});
|
||||
|
||||
function syncButtons() {
|
||||
var cur = document.documentElement.getAttribute('data-theme') || 'dark';
|
||||
updateButtons(cur);
|
||||
document.querySelectorAll('[data-theme-pick]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () {
|
||||
apply(btn.getAttribute('data-theme-pick'));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', syncButtons);
|
||||
} else {
|
||||
syncButtons();
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user