Skip to content

Commit 617a037

Browse files
fix(pagination) fixed swiper Infinite loop scroll jumping (#7690)
* fix(pagination) Swiper Infinite loop scroll jumping * Update pagination.mjs --------- Co-authored-by: Vladimir Kharlampidi <[email protected]>
1 parent 94173da commit 617a037

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/modules/pagination/pagination.mjs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ export default function Pagination({ swiper, extendParams, on, emit }) {
7070
}
7171
}
7272

73+
function getMoveDirection(prevIndex, nextIndex, length) {
74+
prevIndex = prevIndex % length;
75+
nextIndex = nextIndex % length;
76+
if (nextIndex === prevIndex + 1) {
77+
return 'next';
78+
} else if (nextIndex === prevIndex - 1) {
79+
return 'previous';
80+
}
81+
return;
82+
}
7383
function onBulletClick(e) {
7484
const bulletEl = e.target.closest(classesToSelector(swiper.params.pagination.bulletClass));
7585
if (!bulletEl) {
@@ -79,7 +89,14 @@ export default function Pagination({ swiper, extendParams, on, emit }) {
7989
const index = elementIndex(bulletEl) * swiper.params.slidesPerGroup;
8090
if (swiper.params.loop) {
8191
if (swiper.realIndex === index) return;
82-
swiper.slideToLoop(index);
92+
const moveDirection = getMoveDirection(swiper.realIndex, index, swiper.slides.length);
93+
if (moveDirection === 'next') {
94+
swiper.slideNext();
95+
} else if (moveDirection === 'previous') {
96+
swiper.slidePrev();
97+
} else {
98+
swiper.slideToLoop(index);
99+
}
83100
} else {
84101
swiper.slideTo(index);
85102
}

0 commit comments

Comments
 (0)