Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ <h2 class="section-title">Contact</h2>
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;
Expand Down Expand Up @@ -219,6 +221,22 @@ <h2 class="section-title">Contact</h2>
});
}

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;
Expand Down Expand Up @@ -251,6 +269,7 @@ <h2 class="section-title">Contact</h2>
}

if (!fromScroll) {
beginProgrammaticScroll();
scrollTabToCenter(index);
}

Expand All @@ -262,6 +281,7 @@ <h2 class="section-title">Contact</h2>
function scheduleScrollSync() {
if (!carousel) return;
if (scrollDebounce) clearTimeout(scrollDebounce);
if (programmaticScroll) return;
scrollDebounce = setTimeout(function () {
scrollDebounce = null;
var idx = indexFromCenter();
Expand All @@ -272,6 +292,7 @@ <h2 class="section-title">Contact</h2>

if (carousel) {
carousel.addEventListener('scroll', scheduleScrollSync, { passive: true });
carousel.addEventListener('scrollend', endProgrammaticScroll, { passive: true });
}

function clearScrollDebounce() {
Expand Down Expand Up @@ -314,7 +335,7 @@ <h2 class="section-title">Contact</h2>
tabs.forEach(function (t, i) {
if (t.classList.contains('is-active')) initialIndex = i;
});
setActive(initialIndex, false, false);
setActive(initialIndex, false, true);
})();
</script>
</body>
Expand Down