// Wait for DOM to be ready document.addEventListener("DOMContentLoaded", function () { AOS.init({ duration: 800, easing: "ease-in-out", once: true, }); // Navbar scroll effect const navbar = document.querySelector(".navbar"); // Initial check for scroll position if (window.scrollY > 100) { navbar.classList.add("scrolled"); } // Add scroll event listener window.addEventListener("scroll", function () { if (window.scrollY > 100) { navbar.classList.add("scrolled"); } else { navbar.classList.remove("scrolled"); } }); // Statistics counter animation const statNumbers = document.querySelectorAll(".stat-number"); const animateCounter = (element) => { const target = parseInt(element.getAttribute("data-target")); const duration = 2000; // 2 seconds const increment = target / (duration / 16); // 60fps let current = 0; const updateCounter = () => { current += increment; if (current < target) { // Format number with commas or abbreviations if (target >= 1000000) { element.textContent = (current / 1000000).toFixed(1) + "M+"; } else if (target >= 1000) { element.textContent = (current / 1000).toFixed(0) + "K+"; } else { element.textContent = Math.floor(current) + "+"; } requestAnimationFrame(updateCounter); } else { // Final value if (target >= 1000000) { element.textContent = (target / 1000000).toFixed(0) + "M+"; } else if (target >= 1000) { element.textContent = (target / 1000).toFixed(0) + "K+"; } else { element.textContent = target + "+"; } } }; updateCounter(); }; // Intersection Observer for counter animation const observerOptions = { threshold: 0.5, rootMargin: "0px", }; const observer = new IntersectionObserver((entries) => { entries.forEach((entry) => { if ( entry.isIntersecting && !entry.target.classList.contains("animated") ) { entry.target.classList.add("animated"); animateCounter(entry.target); } }); }, observerOptions); statNumbers.forEach((stat) => observer.observe(stat)); });