document.addEventListener('DOMContentLoaded', () => { // Smooth scroll for anchor links document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); document.querySelector(this.getAttribute('href')).scrollIntoView({ behavior: 'smooth' }); }); }); // Add animation classes to elements as they come into view const animateOnScroll = () => { const elements = document.querySelectorAll('.fade-in, .slide-up'); elements.forEach(element => { const elementPosition = element.getBoundingClientRect().top; const screenPosition = window.innerHeight / 1.3; if (elementPosition < screenPosition) { element.classList.add('animate'); } }); }; window.addEventListener('scroll', animateOnScroll); animateOnScroll(); // Run once on page load }); // Theme switcher (example - can be expanded) function toggleTheme() { const html = document.documentElement; html.classList.toggle('dark'); localStorage.setItem('theme', html.classList.contains('dark') ? 'dark' : 'light'); } // Check for saved theme preference if (localStorage.getItem('theme') === 'dark') { document.documentElement.classList.add('dark'); }