let startX; // Posizione iniziale del tocco const swipeThreshold = 90; // Riduce la sensibilità: richiede uno swipe più lungo if (Math.abs(diffX) > swipeThreshold) { // Soglia del movimento per cambiare slide const previousSlide = slides[currentSlideIndex]; const outgoingClass = step > 0 ? 'swipe-left' : 'swipe-right'; if (previousSlide) { previousSlide.classList.remove('swipe-left', 'swipe-right', 'swipe-enter', 'from-left', 'from-right'); previousSlide.classList.add(outgoingClass); previousSlide.addEventListener('animationend', () => { previousSlide.classList.remove('swipe-left', 'swipe-right'); }, { once: true }); } const incomingSlide = slides[currentSlideIndex]; if (incomingSlide) { incomingSlide.classList.remove('swipe-left', 'swipe-right', 'swipe-enter', 'from-left', 'from-right'); void incomingSlide.offsetWidth; // Force reflow to restart animation incomingSlide.classList.add('swipe-enter', step > 0 ? 'from-right' : 'from-left'); incomingSlide.addEventListener('animationend', () => { incomingSlide.classList.remove('swipe-enter', 'from-left', 'from-right'); }, { once: true }); } carousel.style.transition = "transform 0.45s ease"; transition: transform 0.45s ease, opacity 0.45s ease, box-shadow 0.45s ease; } .book.swipe-left { animation: swipeOutLeft 0.45s ease forwards; } .book.swipe-right { animation: swipeOutRight 0.45s ease forwards; } .book.swipe-enter { box-shadow: 0 12px 24px rgba(0, 0, 0, 0.18); } .book.swipe-enter.from-right { animation: swipeEnterFromRight 0.5s ease both; } .book.swipe-enter.from-left { animation: swipeEnterFromLeft 0.5s ease both; } @keyframes swipeOutLeft { to { transform: translateX(-35%) rotate(-6deg) scale(0.95); opacity: 0; } } @keyframes swipeOutRight { to { transform: translateX(35%) rotate(6deg) scale(0.95); opacity: 0; } } @keyframes swipeEnterFromRight { from { transform: translateX(40%) rotate(5deg); opacity: 0; } to { transform: translateX(0) rotate(0deg); opacity: 1; } } @keyframes swipeEnterFromLeft { from { transform: translateX(-40%) rotate(-5deg); opacity: 0; } to { transform: translateX(0) rotate(0deg); opacity: 1; }