optimized js
This commit is contained in:
@@ -37,15 +37,22 @@ class ThemeManager {
|
||||
document.documentElement.setAttribute('data-theme', newTheme);
|
||||
this.updateIcon(!isDark);
|
||||
localStorage.setItem('theme', newTheme);
|
||||
|
||||
|
||||
// Lazy load sound only when needed
|
||||
if (!this.sound && this.soundSrc) {
|
||||
this.sound = new Audio(this.soundSrc);
|
||||
}
|
||||
|
||||
|
||||
if (this.sound) {
|
||||
this.sound.play().catch(() => {});
|
||||
}
|
||||
|
||||
// Use requestAnimationFrame for better performance on transition
|
||||
requestAnimationFrame(() => {
|
||||
setTimeout(() => {
|
||||
document.body.classList.remove('theme-transition');
|
||||
}, 300);
|
||||
});
|
||||
}
|
||||
|
||||
updateIcon(isDark) {
|
||||
@@ -56,6 +63,7 @@ class ThemeManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Initialize when content is loaded
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', () => new ThemeManager());
|
||||
|
||||
Reference in New Issue
Block a user