From 8bef84d68c44b93757585cb037f7448cc99f7c71 Mon Sep 17 00:00:00 2001 From: Vladimir Kharlampidi Date: Wed, 18 Oct 2023 15:56:00 +0300 Subject: [PATCH] fix(autoplay): fix negative autoplay values after stop/start, fix autoplay with free mode fixes #7084 --- src/modules/autoplay/autoplay.mjs | 19 ++++++++++++++++--- src/modules/free-mode/free-mode.mjs | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/modules/autoplay/autoplay.mjs b/src/modules/autoplay/autoplay.mjs index 905312ad5..18853fd3a 100644 --- a/src/modules/autoplay/autoplay.mjs +++ b/src/modules/autoplay/autoplay.mjs @@ -14,7 +14,7 @@ export default function Autoplay({ swiper, extendParams, on, emit, params }) { enabled: false, delay: 3000, waitForTransition: true, - disableOnInteraction: true, + disableOnInteraction: false, stopOnLastSlide: false, reverseDirection: false, pauseOnMouseEnter: false, @@ -25,7 +25,7 @@ export default function Autoplay({ swiper, extendParams, on, emit, params }) { let autoplayDelayTotal = params && params.autoplay ? params.autoplay.delay : 3000; let autoplayDelayCurrent = params && params.autoplay ? params.autoplay.delay : 3000; let autoplayTimeLeft; - let autoplayStartTime = new Date().getTime; + let autoplayStartTime = new Date().getTime(); let wasPaused; let isTouched; let pausedByTouch; @@ -134,6 +134,7 @@ export default function Autoplay({ swiper, extendParams, on, emit, params }) { }; const start = () => { + autoplayStartTime = new Date().getTime(); swiper.autoplay.running = true; run(); emit('autoplayStart'); @@ -248,7 +249,7 @@ export default function Autoplay({ swiper, extendParams, on, emit, params }) { if (swiper.params.autoplay.enabled) { attachMouseEvents(); attachDocumentEvents(); - autoplayStartTime = new Date().getTime(); + start(); } }); @@ -261,6 +262,18 @@ export default function Autoplay({ swiper, extendParams, on, emit, params }) { } }); + on('_freeModeStaticRelease', () => { + if (pausedByTouch || pausedByInteraction) { + resume(); + } + }); + on('_freeModeNoMomentumRelease', () => { + if (!swiper.params.autoplay.disableOnInteraction) { + pause(true, true); + } else { + stop(); + } + }); on('beforeTransitionStart', (_s, speed, internal) => { if (swiper.destroyed || !swiper.autoplay.running) return; if (internal || !swiper.params.autoplay.disableOnInteraction) { diff --git a/src/modules/free-mode/free-mode.mjs b/src/modules/free-mode/free-mode.mjs index 802959b9c..1e80dd940 100644 --- a/src/modules/free-mode/free-mode.mjs +++ b/src/modules/free-mode/free-mode.mjs @@ -216,6 +216,7 @@ export default function freeMode({ swiper, extendParams, emit, once }) { } if (!params.freeMode.momentum || timeDiff >= params.longSwipesMs) { + emit('_freeModeStaticRelease'); swiper.updateProgress(); swiper.updateActiveIndex(); swiper.updateSlidesClasses();