Add swiping to Spotlight carousel on mobile. Prevent swiping to different tabs when swiping Spotlight carousels.

This commit is contained in:
HighImKevin
2025-12-04 06:30:41 -05:00
parent dc9e895ef5
commit a7b157deb9
2 changed files with 57 additions and 1 deletions
+6 -1
View File
@@ -400,6 +400,11 @@
.spotlight-tagline {
max-height: 175px !important;
-webkit-line-clamp: 6;
-webkit-line-clamp: 4;
}
.spotlight-item-logo {
max-width: 100%;
height: 125px;
}
}
+51
View File
@@ -1349,6 +1349,57 @@
if (autoPlay) {
startAutoPlay();
}
// Touch swipe handling
let touchStartX = 0;
let touchStartY = 0;
bannerContainer.addEventListener('touchstart', (e) => {
touchStartX = e.touches[0].clientX;
touchStartY = e.touches[0].clientY;
}, { passive: true });
bannerContainer.addEventListener('touchmove', (e) => {
if (!e.touches[0]) return;
const touchX = e.touches[0].clientX;
const touchY = e.touches[0].clientY;
const deltaX = touchX - touchStartX;
const deltaY = touchY - touchStartY;
// If horizontal movement is dominant, prevent vertical scrolling and propagation
if (Math.abs(deltaX) > Math.abs(deltaY)) {
if (e.cancelable) {
e.preventDefault();
e.stopPropagation();
}
}
}, { passive: false });
bannerContainer.addEventListener('touchend', (e) => {
if (!e.changedTouches[0]) return;
const touchEndX = e.changedTouches[0].clientX;
const touchEndY = e.changedTouches[0].clientY;
const deltaX = touchEndX - touchStartX;
const deltaY = touchEndY - touchStartY;
// Threshold for swipe (50px)
if (Math.abs(deltaX) > 50 && Math.abs(deltaX) > Math.abs(deltaY)) {
// Stop propagation to prevent parent handlers (like tab switching)
e.stopPropagation();
if (deltaX > 0) {
// Swipe right (previous)
goToItem((currentIndex - 1 + items.length) % items.length, true);
} else {
// Swipe left (next)
goToItem((currentIndex + 1) % items.length, true);
}
}
}, { passive: true });
container.appendChild(bannerContainer);