document.addEventListener('DOMContentLoaded', function() { // Add animations to elements when 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.2; if (elementPosition < screenPosition) { element.classList.add('animate'); } }); }; window.addEventListener('scroll', animateOnScroll); animateOnScroll(); // Run once on load // Smooth scroll 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' }); } }); }); // Video play/pause control for mobile const heroVideo = document.querySelector('video'); if (heroVideo) { heroVideo.muted = true; // On mobile, play video only when in view if (window.innerWidth < 768) { const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { heroVideo.play(); } else { heroVideo.pause(); } }); }, { threshold: 0.5 }); observer.observe(heroVideo); } } });