============================================================ */ document.addEventListener("DOMContentLoaded", () => { initScrollReveal(); initSmoothScroll(); }); /* ============================ SCROLL REVEAL Adds .is-visible to any element with .dd-reveal when it enters the viewport. ============================ */ function initScrollReveal() { const items = document.querySelectorAll(".dd-reveal"); if (!items.length) return; const observer = new IntersectionObserver( (entries) => { entries.forEach((entry) => { if (!entry.isIntersecting) return; const delay = parseInt(entry.target.dataset.delay || "0", 10); setTimeout(() => entry.target.classList.add("is-visible"), delay); observer.unobserve(entry.target); }); }, { threshold: 0.1, rootMargin: "0px 0px -40px 0px" } ); items.forEach((item) => observer.observe(item)); } /* ============================ SMOOTH SCROLL Handles all anchor links on the page. ============================ */ function initSmoothScroll() { document.querySelectorAll('a[href^="#"]').forEach((link) => { link.addEventListener("click", (e) => { const id = link.getAttribute("href"); if (!id || id === "#") return; const target = document.querySelector(id); if (!target) return; e.preventDefault(); target.scrollIntoView({ behavior: "smooth", block: "start" }); }); }); }