add touch swipe to overlay carousel

This commit is contained in:
Your Name 2026-01-02 01:53:15 -05:00
parent 36fc9a7dd1
commit e3a67347fd
1 changed files with 14 additions and 0 deletions

View File

@ -519,6 +519,20 @@ function initModalGallery(modalWrap, gallery) {
});
});
setActive(0);
let touchStartX = 0;
const touchThreshold = 30;
heroImg.addEventListener("touchstart", (event) => {
if (!event.touches?.length) return;
touchStartX = event.touches[0].clientX;
});
heroImg.addEventListener("touchend", (event) => {
if (!event.changedTouches?.length) return;
const dx = event.changedTouches[0].clientX - touchStartX;
if (Math.abs(dx) < touchThreshold) return;
const direction = dx > 0 ? -1 : 1;
const nextIndex = (activeIndex + direction + gallery.length) % gallery.length;
setActive(nextIndex);
});
}
function openImageLightbox(src) {