Skip to content

Commit

Permalink
Fix initial slide index shift with centeredSlides and slidesPerView auto
Browse files Browse the repository at this point in the history
- 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 committed Feb 18, 2024
1 parent fc308b3 commit 1e29c78
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 1e29c78

Please sign in to comment.