From 43bf429a35b8ae7452c5825e893062d8e4e2be2e Mon Sep 17 00:00:00 2001 From: Vladimir Kharlampidi Date: Wed, 7 Dec 2022 15:05:16 +0300 Subject: [PATCH] fix(autoplay): correct support for virtual slides delay + fix for stopping autoplay on click --- src/modules/autoplay/autoplay.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/modules/autoplay/autoplay.js b/src/modules/autoplay/autoplay.js index bb208edef..302b0e4bf 100644 --- a/src/modules/autoplay/autoplay.js +++ b/src/modules/autoplay/autoplay.js @@ -59,10 +59,16 @@ export default function Autoplay({ swiper, extendParams, on, emit, params }) { }; const getSlideDelay = () => { - const currentSlideDelay = parseInt( - swiper.slides[swiper.activeIndex].getAttribute('data-swiper-autoplay'), - 10, - ); + let activeSlideEl; + if (swiper.virtual && swiper.params.virtual.enabled) { + activeSlideEl = swiper.slides.filter((slideEl) => + slideEl.classList.contains('swiper-slide-active'), + )[0]; + } else { + activeSlideEl = swiper.slides[swiper.activeIndex]; + } + if (!activeSlideEl) return undefined; + const currentSlideDelay = parseInt(activeSlideEl.getAttribute('data-swiper-autoplay'), 10); return currentSlideDelay; }; @@ -279,11 +285,11 @@ export default function Autoplay({ swiper, extendParams, on, emit, params }) { }); on('touchEnd', () => { - if (swiper.destroyed || !swiper.autoplay.running) return; + if (swiper.destroyed || !swiper.autoplay.running || !isTouched) return; clearTimeout(touchStartTimeout); clearTimeout(timeout); - if (!isTouched || swiper.params.autoplay.disableOnInteraction) { + if (swiper.params.autoplay.disableOnInteraction) { pausedByTouch = false; isTouched = false; return;