Skip to content

Commit

Permalink
fix(autoplay): fix negative autoplay values after stop/start, fix aut…
Browse files Browse the repository at this point in the history
…oplay with free mode

fixes #7084
  • Loading branch information
nolimits4web committed Oct 18, 2023
1 parent cec33b9 commit 8bef84d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/modules/autoplay/autoplay.mjs
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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();
}
});
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/modules/free-mode/free-mode.mjs
Expand Up @@ -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();
Expand Down

0 comments on commit 8bef84d

Please sign in to comment.