Spaces:
Running
Running
File size: 2,218 Bytes
51910aa 85363ff 51910aa 8d56b04 145f4ca 51910aa 7affbda 51910aa 8d56b04 51910aa 8d56b04 51910aa 85363ff 8d56b04 51910aa 7affbda 51910aa 0ecb290 51910aa 7affbda 51910aa 7affbda 145f4ca 85363ff 51910aa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if(targetId === '#') return;
const targetElement = document.querySelector(targetId);
if(targetElement) {
window.scrollTo({
top: targetElement.offsetTop - 100,
behavior: 'smooth'
});
}
});
});
// Dark/Light mode toggle
function toggleDarkMode() {
const isDark = document.documentElement.classList.toggle('dark');
document.documentElement.classList.toggle('light', !isDark);
localStorage.setItem('darkMode', isDark ? 'true' : 'false');
// Dispatch custom event for navbar to listen to
window.dispatchEvent(new CustomEvent('themeChanged', {
detail: { isDark }
}));
}
function updateModeIcon(isDark) {
window.dispatchEvent(new CustomEvent('updateThemeIcon', {
detail: { isDark }
}));
}
// Listen for navbar toggle requests
window.addEventListener('toggleTheme', () => {
toggleDarkMode();
});
// Initialize mode preference - default to light theme
document.addEventListener('DOMContentLoaded', () => {
// Set default to light mode
const storedMode = localStorage.getItem('darkMode');
if (storedMode === 'true') {
document.documentElement.classList.add('dark');
document.documentElement.classList.remove('light');
} else {
document.documentElement.classList.remove('dark');
document.documentElement.classList.add('light');
localStorage.setItem('darkMode', 'false');
}
// Update icon on load
const isDark = document.documentElement.classList.contains('dark');
updateModeIcon(isDark);
});
// Intersection Observer for animations
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if(entry.isIntersecting) {
entry.target.classList.add('fade-in');
}
});
}, {
threshold: 0.1
});
document.querySelectorAll('.animate-on-scroll').forEach(el => {
observer.observe(el);
});
|