Skip to content

Commit

Permalink
fix(core): fix loop when slidesPerGroup is not even to number of slides
Browse files Browse the repository at this point in the history
fixes #6412
  • Loading branch information
nolimits4web committed Feb 28, 2023
1 parent 7883408 commit f998115
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/core/loop/loopFix.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ export default function loopFix({
let slidesAppended = 0;
// prepend last slides before start
if (activeSlideIndex < loopedSlides) {
slidesPrepended = loopedSlides - activeSlideIndex;
slidesPrepended = Math.max(loopedSlides - activeSlideIndex, params.slidesPerGroup);
for (let i = 0; i < loopedSlides - activeSlideIndex; i += 1) {
const index = i - Math.floor(i / slides.length) * slides.length;
prependSlidesIndexes.push(slides.length - index - 1);
}
} else if (activeSlideIndex /* + slidesPerView */ > swiper.slides.length - loopedSlides * 2) {
slidesAppended = activeSlideIndex - (swiper.slides.length - loopedSlides * 2);
slidesAppended = Math.max(
activeSlideIndex - (swiper.slides.length - loopedSlides * 2),
params.slidesPerGroup,
);
for (let i = 0; i < slidesAppended; i += 1) {
const index = i - Math.floor(i / slides.length) * slides.length;
appendSlidesIndexes.push(index);
Expand All @@ -85,6 +88,7 @@ export default function loopFix({
slidesEl.append(swiper.slides[index]);
});
}

swiper.recalcSlides();
if (params.watchSlidesProgress) {
swiper.updateSlidesOffset();
Expand Down

0 comments on commit f998115

Please sign in to comment.