You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
41 lines
1.1 KiB
|
3 years ago
|
export default function loopFix() {
|
||
|
|
const swiper = this;
|
||
|
|
swiper.emit('beforeLoopFix');
|
||
|
|
const {
|
||
|
|
activeIndex,
|
||
|
|
slides,
|
||
|
|
loopedSlides,
|
||
|
|
allowSlidePrev,
|
||
|
|
allowSlideNext,
|
||
|
|
snapGrid,
|
||
|
|
rtlTranslate: rtl
|
||
|
|
} = swiper;
|
||
|
|
let newIndex;
|
||
|
|
swiper.allowSlidePrev = true;
|
||
|
|
swiper.allowSlideNext = true;
|
||
|
|
const snapTranslate = -snapGrid[activeIndex];
|
||
|
|
const diff = snapTranslate - swiper.getTranslate();
|
||
|
|
|
||
|
|
if (activeIndex < loopedSlides) {
|
||
|
|
newIndex = slides.length - loopedSlides * 3 + activeIndex;
|
||
|
|
newIndex += loopedSlides;
|
||
|
|
const slideChanged = swiper.slideTo(newIndex, 0, false, true);
|
||
|
|
|
||
|
|
if (slideChanged && diff !== 0) {
|
||
|
|
swiper.setTranslate((rtl ? -swiper.translate : swiper.translate) - diff);
|
||
|
|
}
|
||
|
|
} else if (activeIndex >= slides.length - loopedSlides) {
|
||
|
|
newIndex = -slides.length + activeIndex + loopedSlides;
|
||
|
|
newIndex += loopedSlides;
|
||
|
|
const slideChanged = swiper.slideTo(newIndex, 0, false, true);
|
||
|
|
|
||
|
|
if (slideChanged && diff !== 0) {
|
||
|
|
swiper.setTranslate((rtl ? -swiper.translate : swiper.translate) - diff);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
swiper.allowSlidePrev = allowSlidePrev;
|
||
|
|
swiper.allowSlideNext = allowSlideNext;
|
||
|
|
swiper.emit('loopFix');
|
||
|
|
}
|