document.addEventListener('DOMContentLoaded', function() { // Animate elements when they come into view const animateOnScroll = () => { const elements = document.querySelectorAll('.fade-in'); elements.forEach(element => { const elementPosition = element.getBoundingClientRect().top; const screenPosition = window.innerHeight / 1.2; if (elementPosition < screenPosition) { element.classList.add('animate-fadeIn'); } }); }; // Initialize animations on load and scroll window.addEventListener('load', animateOnScroll); window.addEventListener('scroll', animateOnScroll); // 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) { targetElement.scrollIntoView({ behavior: 'smooth' }); } }); }); });