Skip to content

Commit

Permalink
fix(core): fix initial slide index shift with centeredSlides and slid…
Browse files Browse the repository at this point in the history
…esPerView auto (#7319)

- 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
  • Loading branch information
yasuhiro-yamamoto authored Feb 27, 2024
1 parent da63bef commit cae9c2d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/loop/loopFix.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export default function loopFix({
if (byMousewheel) {
swiper.setTranslate(swiper.translate - diff);
} else {
swiper.slideTo(activeIndex + slidesPrepended, 0, false, true);
swiper.slideTo(activeIndex + Math.ceil(slidesPrepended), 0, false, true);
if (setTranslate) {
swiper.touchEventsData.startTranslate = swiper.touchEventsData.startTranslate - diff;
swiper.touchEventsData.currentTranslate =
Expand Down

0 comments on commit cae9c2d

Please sign in to comment.