diff --git a/src/modules/pagination/pagination.mjs b/src/modules/pagination/pagination.mjs index c773b993e..fc6486c70 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(prevIndex, nextIndex, length) { + prevIndex = prevIndex % length; + nextIndex = nextIndex % length; + if (nextIndex === prevIndex + 1) { + return 'next'; + } else if (nextIndex === prevIndex - 1) { + return 'previous'; + } + return; + } function onBulletClick(e) { const bulletEl = e.target.closest(classesToSelector(swiper.params.pagination.bulletClass)); if (!bulletEl) { @@ -79,7 +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; - swiper.slideToLoop(index); + const moveDirection = getMoveDirection(swiper.realIndex, index, swiper.slides.length); + if (moveDirection === 'next') { + swiper.slideNext(); + } else if (moveDirection === 'previous') { + swiper.slidePrev(); + } else { + swiper.slideToLoop(index); + } } else { swiper.slideTo(index); }