// Homepage banner strip: a seamless, constant-speed loop. // The images are copied once so a second set follows the first; the strip // moves left by exactly one set's width and then repeats, so the seam never // shows. Speed is in pixels per second, so it looks the same on any screen. (function () { const SPEED = 40; // px per second const strip = document.querySelector(".marquee"); if (!strip || !strip.animate) return; const originals = [...strip.children]; if (originals.length === 0) return; originals.forEach(img => strip.append(img.cloneNode(true))); const firstCopy = strip.children[originals.length]; const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)"); let offscreen = false; let animation = null; let setWidth = 0; // Width of one set: where the copy starts relative to the original function measure() { return firstCopy.offsetLeft - originals[0].offsetLeft; } function keyframes(width) { return [ { transform: "translateX(0)" }, { transform: `translateX(${-width}px)` }, ]; } function update() { const width = measure(); if (width <= 0 || width === setWidth) return; const duration = (width / SPEED) * 1000; if (!animation) { animation = strip.animate(keyframes(width), { duration, iterations: Infinity }); } else { // Keep the same place in the loop when the size changes (window resized) const oldDuration = animation.effect.getTiming().duration; const progress = (animation.currentTime % oldDuration) / oldDuration; animation.effect.setKeyframes(keyframes(width)); animation.effect.updateTiming({ duration }); animation.currentTime = progress * duration; } setWidth = width; syncPlayState(); } // Stop when the hero is scrolled away or the visitor prefers less motion function syncPlayState() { if (!animation) return; if (offscreen || reducedMotion.matches) animation.pause(); else animation.play(); } new ResizeObserver(update).observe(strip); new IntersectionObserver(entries => { offscreen = !entries[0].isIntersecting; syncPlayState(); }).observe(strip.parentElement); reducedMotion.addEventListener("change", syncPlayState); update(); })();