the-khmer23-mandate / script.js
steake's picture
change the switch toggle to a button theme toggle
e128622 verified
raw
history blame contribute delete
901 Bytes
// Theme toggle
const toggleBtn = document.getElementById('themeToggleBtn');
const html = document.documentElement;
const currentTheme = html.getAttribute('data-theme');
function updateButtonText(theme) {
toggleBtn.textContent = theme === 'dark' ? 'Light' : 'Dark';
}
// Initialize
updateButtonText(currentTheme);
toggleBtn.addEventListener('click', () => {
const newTheme = html.getAttribute('data-theme') === 'dark' ? 'light' : 'dark';
html.setAttribute('data-theme', newTheme);
updateButtonText(newTheme);
});
// Intersection Observer for fade-ins
const observer = new IntersectionObserver(
(entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('fade-in');
observer.unobserve(entry.target);
}
});
},
{ threshold: 0.2 }
);
document.querySelectorAll('gallery-item').forEach(el => observer.observe(el));