diff --git a/web/modules/custom/riverside_pt/js/components/rpt-testimonials.js b/web/modules/custom/riverside_pt/js/components/rpt-testimonials.js index 942dec1..aaa6997 100644 --- a/web/modules/custom/riverside_pt/js/components/rpt-testimonials.js +++ b/web/modules/custom/riverside_pt/js/components/rpt-testimonials.js @@ -1,5 +1,5 @@ import { h, render } from "https://esm.sh/preact@10"; -import { useState, useRef } from "https://esm.sh/preact@10/hooks"; +import { useState, useEffect, useRef } from "https://esm.sh/preact@10/hooks"; import { html } from "https://esm.sh/htm@3/preact"; const TESTIMONIALS = [ @@ -54,6 +54,27 @@ function Testimonials() { setLeft(function (l) { return Math.max(-maxL, l - STEP); }); }; + var leftRef = useRef(left); + leftRef.current = left; + + useEffect(function () { + var timer; + function onResize() { + clearTimeout(timer); + timer = setTimeout(function () { + var max = measureMax(); + if (-leftRef.current > max) { + setLeft(-max); + } + }, 150); + } + window.addEventListener("resize", onResize); + return function () { + clearTimeout(timer); + window.removeEventListener("resize", onResize); + }; + }, []); + var atStart = left >= 0; return html`