From 125c7ff96074bd64a3cbbf2a35d8cef8c621483f Mon Sep 17 00:00:00 2001 From: StarsLeopad <1240056120@qq.com> Date: Mon, 19 Aug 2024 19:43:41 +0800 Subject: [PATCH 1/2] fix(pagination) Swiper Infinite loop scroll jumping --- src/modules/pagination/pagination.mjs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/modules/pagination/pagination.mjs b/src/modules/pagination/pagination.mjs index c773b993e..a9d7ef01c 100644 --- a/src/modules/pagination/pagination.mjs +++ b/src/modules/pagination/pagination.mjs @@ -70,6 +70,16 @@ export default function Pagination({ swiper, extendParams, on, emit }) { } } + function getMoveDirection(preIndex, nextIndex, length) { + preIndex = preIndex % length; + nextIndex = nextIndex % length; + if (nextIndex === preIndex + 1) { + return 'next'; + } else if (nextIndex === preIndex - 1) { + return 'previous'; + } + return; + } function onBulletClick(e) { const bulletEl = e.target.closest(classesToSelector(swiper.params.pagination.bulletClass)); if (!bulletEl) { @@ -79,6 +89,14 @@ export default function Pagination({ swiper, extendParams, on, emit }) { const index = elementIndex(bulletEl) * swiper.params.slidesPerGroup; if (swiper.params.loop) { if (swiper.realIndex === index) return; + if (getMoveDirection(swiper.realIndex, index, swiper.slides.length) === 'next') { + swiper.slideNext(); + return; + } + if (getMoveDirection(swiper.realIndex, index, swiper.slides.length) === 'previous') { + swiper.slidePrev(); + return; + } swiper.slideToLoop(index); } else { swiper.slideTo(index); From d68361d8ea1bcfce5e795eec71332c2d0c0a56f8 Mon Sep 17 00:00:00 2001 From: Vladimir Kharlampidi Date: Wed, 21 Aug 2024 12:20:50 +0300 Subject: [PATCH 2/2] Update pagination.mjs --- src/modules/pagination/pagination.mjs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/modules/pagination/pagination.mjs b/src/modules/pagination/pagination.mjs index a9d7ef01c..fc6486c70 100644 --- a/src/modules/pagination/pagination.mjs +++ b/src/modules/pagination/pagination.mjs @@ -70,12 +70,12 @@ export default function Pagination({ swiper, extendParams, on, emit }) { } } - function getMoveDirection(preIndex, nextIndex, length) { - preIndex = preIndex % length; + function getMoveDirection(prevIndex, nextIndex, length) { + prevIndex = prevIndex % length; nextIndex = nextIndex % length; - if (nextIndex === preIndex + 1) { + if (nextIndex === prevIndex + 1) { return 'next'; - } else if (nextIndex === preIndex - 1) { + } else if (nextIndex === prevIndex - 1) { return 'previous'; } return; @@ -89,15 +89,14 @@ export default function Pagination({ swiper, extendParams, on, emit }) { const index = elementIndex(bulletEl) * swiper.params.slidesPerGroup; if (swiper.params.loop) { if (swiper.realIndex === index) return; - if (getMoveDirection(swiper.realIndex, index, swiper.slides.length) === 'next') { + const moveDirection = getMoveDirection(swiper.realIndex, index, swiper.slides.length); + if (moveDirection === 'next') { swiper.slideNext(); - return; - } - if (getMoveDirection(swiper.realIndex, index, swiper.slides.length) === 'previous') { + } else if (moveDirection === 'previous') { swiper.slidePrev(); - return; + } else { + swiper.slideToLoop(index); } - swiper.slideToLoop(index); } else { swiper.slideTo(index); }