add touch swipe to overlay carousel
This commit is contained in:
parent
36fc9a7dd1
commit
e3a67347fd
|
|
@ -519,6 +519,20 @@ function initModalGallery(modalWrap, gallery) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
setActive(0);
|
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) {
|
function openImageLightbox(src) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue