Skip to content

Commit 1e29c78

Browse files
Fix initial slide index shift with centeredSlides and slidesPerView auto
- Originally observed issue when initialSlide was 0 but reproduced in other cases - Investigation found activeColIndexWithShift calculation in loopFix.mjs was adding 0.5 when centeredSlides true, causing slidesPrepended to be decimal number in some cases - Non-integer slidesPrepended value then gets rounded down in snapIndex calculation in slideTo.mjs, causing initial slide index to be less than intended - Fix by using Math.ceil to round up the slide index variable passed to the slideTo method as argument in loopFix.mjs, ensuring an integer index value is passed to slideTo
1 parent fc308b3 commit 1e29c78

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/core/loop/loopFix.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export default function loopFix({
158158
if (byMousewheel) {
159159
swiper.setTranslate(swiper.translate - diff);
160160
} else {
161-
swiper.slideTo(activeIndex + slidesPrepended, 0, false, true);
161+
swiper.slideTo(activeIndex + Math.ceil(slidesPrepended), 0, false, true);
162162
if (setTranslate) {
163163
swiper.touchEventsData.startTranslate = swiper.touchEventsData.startTranslate - diff;
164164
swiper.touchEventsData.currentTranslate =

0 commit comments

Comments
 (0)