document.addEventListener("DOMContentLoaded", function() { // If IntersectionObserver isn't supported, just add in-view immediately if (!("IntersectionObserver" in window)) { document.querySelectorAll(".bg-pan").forEach(function(el) { el.classList.add("in-view"); }); return; } var observer = new IntersectionObserver(function(entries) { entries.forEach(function(entry) { if (entry.isIntersecting) { entry.target.classList.add("in-view"); // Stop observing once triggered (optional) observer.unobserve(entry.target); } }); }, { threshold: 0.2 // 20% of element is visible }); document.querySelectorAll(".bg-pan").forEach(function(el) { observer.observe(el); }); });