(function () { const selector = '.sd-scroll-text-reveal'; let targets = []; function init() { if (window.matchMedia( '(prefers-reduced-motion: reduce)' ).matches) return; document.querySelectorAll(selector).forEach(function (widget) { if (widget.dataset.sdRevealReady) return; // Animate only the first heading inside this widget const heading = widget.querySelector( 'h1, h2, h3, h4, h5, h6' ); if (!heading) return; heading.classList.add('sd-scrub-heading'); widget.dataset.sdRevealReady = 'true'; targets.push(heading); }); update(); } function update() { const start = window.innerHeight * 0.45; const end = window.innerHeight * 0.15; const distance = start - end; targets.forEach(function (heading) { const top = heading.getBoundingClientRect().top; // Progress increases while scrolling down. // 0 = fully visible, 1 = fully hidden. const progress = Math.max( 0, Math.min(1, (start - top) / distance) ); heading.style.clipPath = 'inset(' + (progress * 100) + '% 0 0 0)'; heading.style.transform = 'translateY(' + (-18 * progress) + 'px)'; }); } let ticking = false; function requestUpdate() { if (ticking) return; ticking = true; window.requestAnimationFrame(function () { update(); ticking = false; }); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } window.addEventListener('scroll', requestUpdate, { passive: true }); window.addEventListener('resize', requestUpdate); })();