Skip to content

Commit

Permalink
fix(core): fix loop on centeredSlides slide to beginning
Browse files Browse the repository at this point in the history
fixes #7011
  • Loading branch information
nolimits4web committed Sep 6, 2023
1 parent 1cd412e commit c496835
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/modules/pagination/pagination.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,28 @@ export default function Pagination({ swiper, extendParams, on, emit }) {
const realIndex = swiper.realIndex;
const newSlideIndex = swiper.getSlideIndexByData(index);
const currentSlideIndex = swiper.getSlideIndexByData(swiper.realIndex);
if (newSlideIndex > swiper.slides.length - swiper.loopedSlides) {
const loopFix = (dir) => {
const indexBeforeLoopFix = swiper.activeIndex;
swiper.loopFix({
direction: newSlideIndex > currentSlideIndex ? 'next' : 'prev',
direction: dir,
activeSlideIndex: newSlideIndex,
slideTo: false,
});
const indexAfterFix = swiper.activeIndex;
if (indexBeforeLoopFix === indexAfterFix) {
swiper.slideToLoop(realIndex, 0, false, true);
}
};
if (newSlideIndex > swiper.slides.length - swiper.loopedSlides) {
loopFix(newSlideIndex > currentSlideIndex ? 'next' : 'prev');
} else if (swiper.params.centeredSlides) {
const slidesPerView =
swiper.params.slidesPerView === 'auto'
? swiper.slidesPerViewDynamic()
: Math.ceil(parseFloat(swiper.params.slidesPerView, 10));
if (newSlideIndex < Math.floor(slidesPerView / 2)) {
loopFix('prev');
}
}

swiper.slideToLoop(index);
Expand Down

0 comments on commit c496835

Please sign in to comment.