// Intersection Observer for Counter Animation const counterObserver = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { const counters = entry.target.querySelectorAll('.counter'); counters.forEach(counter => { const target = parseInt(counter.getAttribute('data-target')); const duration = 2000; // 2 seconds const step = target / (duration / 16); // 60fps let current = 0; const updateCounter = () => { current += step; if (current < target) { if (target > 1000) { counter.innerText = '$' + Math.floor(current).toLocaleString(); } else if (target > 100) { counter.innerText = (current / 10).toFixed(1) + '%'; } else { counter.innerText = Math.floor(current); } requestAnimationFrame(updateCounter); } else { if (target > 1000) { counter.innerText = '$' + target.toLocaleString(); } else if (target > 100) { counter.innerText = (target / 10).toFixed(1) + '%'; } else { counter.innerText = target; } } }; updateCounter(); }); counterObserver.unobserve(entry.target); } }); }, { threshold: 0.5 }); // Observe counter sections document.addEventListener('DOMContentLoaded', () => { const counterSections = document.querySelectorAll('.counter'); if (counterSections.length > 0) { const parent = counterSections[0].closest('section'); if (parent) counterObserver.observe(parent); } // Initialize Feather Icons if (typeof feather !== 'undefined') { feather.replace(); } // Navigation Scroll Effect const nav = document.querySelector('custom-navbar'); if (nav) { window.addEventListener('scroll', () => { if (window.scrollY > 50) { nav.classList.add('nav-scrolled'); } else { nav.classList.remove('nav-scrolled'); } }); } // Smooth Scroll for Anchor Links document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); const target = document.querySelector(this.getAttribute('href')); if (target) { target.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }); }); // Parallax Effect for Hero const hero = document.querySelector('section:first-of-type'); if (hero) { window.addEventListener('scroll', () => { const scrolled = window.pageYOffset; const parallax = hero.querySelector('img'); if (parallax) { parallax.style.transform = `translateY(${scrolled * 0.5}px)`; } }); } // Intersection Observer for Fade-in Elements const fadeObserver = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add('animate-fade-in-up'); fadeObserver.unobserve(entry.target); } }); }, { threshold: 0.1 }); document.querySelectorAll('section').forEach(section => { fadeObserver.observe(section); }); }); // Mobile Menu Toggle function toggleMobileMenu() { const mobileMenu = document.getElementById('mobile-menu'); if (mobileMenu) { mobileMenu.classList.toggle('hidden'); } } // Form Validation Helper function validateForm(formElement) { const inputs = formElement.querySelectorAll('input[required], textarea[required]'); let isValid = true; inputs.forEach(input => { if (!input.value.trim()) { isValid = false; input.classList.add('border-red-500'); } else { input.classList.remove('border-red-500'); } }); return isValid; } // Lazy Loading Images if ('IntersectionObserver' in window) { const imageObserver = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { const img = entry.target; img.src = img.dataset.src || img.src; img.classList.remove('lazy'); imageObserver.unobserve(img); } }); }); document.addEventListener('DOMContentLoaded', () => { document.querySelectorAll('img.lazy').forEach(img => imageObserver.observe(img)); }); }