diff --git a/index.html b/index.html index 62f6e91..1216da6 100644 --- a/index.html +++ b/index.html @@ -191,6 +191,8 @@

Contact

var reduceMotion = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches; var scrollDebounce = null; var lastScrollIndex = -1; + var programmaticScroll = false; + var programmaticScrollTimer = null; function indexFromCenter() { if (!carousel) return 0; @@ -219,6 +221,22 @@

Contact

}); } + function endProgrammaticScroll() { + programmaticScroll = false; + if (programmaticScrollTimer) { + clearTimeout(programmaticScrollTimer); + programmaticScrollTimer = null; + } + } + + function beginProgrammaticScroll() { + programmaticScroll = true; + if (programmaticScrollTimer) { + clearTimeout(programmaticScrollTimer); + } + programmaticScrollTimer = setTimeout(endProgrammaticScroll, reduceMotion ? 120 : 800); + } + function setActive(index, focusTab, fromScroll) { var tab = tabs[index]; if (!tab) return; @@ -251,6 +269,7 @@

Contact

} if (!fromScroll) { + beginProgrammaticScroll(); scrollTabToCenter(index); } @@ -262,6 +281,7 @@

Contact

function scheduleScrollSync() { if (!carousel) return; if (scrollDebounce) clearTimeout(scrollDebounce); + if (programmaticScroll) return; scrollDebounce = setTimeout(function () { scrollDebounce = null; var idx = indexFromCenter(); @@ -272,6 +292,7 @@

Contact

if (carousel) { carousel.addEventListener('scroll', scheduleScrollSync, { passive: true }); + carousel.addEventListener('scrollend', endProgrammaticScroll, { passive: true }); } function clearScrollDebounce() { @@ -314,7 +335,7 @@

Contact

tabs.forEach(function (t, i) { if (t.classList.contains('is-active')) initialIndex = i; }); - setActive(initialIndex, false, false); + setActive(initialIndex, false, true); })();