Skip to content

Commit

Permalink
fix(pagination) fixed swiper Infinite loop scroll jumping (#7690)
Browse files Browse the repository at this point in the history
* fix(pagination) Swiper Infinite loop scroll jumping

* Update pagination.mjs

---------

Co-authored-by: Vladimir Kharlampidi <nolimits4web@gmail.com>
  • Loading branch information
StarsLeopard and nolimits4web authored Aug 21, 2024
1 parent 94173da commit 617a037
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/modules/pagination/pagination.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down

0 comments on commit 617a037

Please sign in to comment.