========================================================== */ document.addEventListener("DOMContentLoaded", function(){ /* Reveal on scroll */ const revealItems = document.querySelectorAll(".scs-reveal"); const revealObserver = new IntersectionObserver((entries)=>{ entries.forEach(entry=>{ if(entry.isIntersecting){ entry.target.classList.add("is-visible"); revealObserver.unobserve(entry.target); } }); }, {threshold:.16}); revealItems.forEach(item=>revealObserver.observe(item)); /* Animated counters */ const counters = document.querySelectorAll("[data-scs-counter]"); const counterObserver = new IntersectionObserver((entries)=>{ entries.forEach(entry=>{ if(entry.isIntersecting){ const el = entry.target; const target = parseInt(el.getAttribute("data-scs-counter"), 10); const prefix = el.getAttribute("data-prefix") || ""; const suffix = el.getAttribute("data-suffix") || ""; let current = 0; const duration = 1400; const start = performance.now(); function update(now){ const progress = Math.min((now - start) / duration, 1); current = Math.floor(progress * target); el.textContent = prefix + current.toLocaleString("es-GT") + suffix; if(progress < 1) requestAnimationFrame(update); } requestAnimationFrame(update); counterObserver.unobserve(el); } }); }, {threshold:.35}); counters.forEach(counter=>counterObserver.observe(counter)); });