1 | export default function loopFix() {
|
2 | const swiper = this;
|
3 | swiper.emit('beforeLoopFix');
|
4 | const {
|
5 | activeIndex,
|
6 | slides,
|
7 | loopedSlides,
|
8 | allowSlidePrev,
|
9 | allowSlideNext,
|
10 | snapGrid,
|
11 | rtlTranslate: rtl
|
12 | } = swiper;
|
13 | let newIndex;
|
14 | swiper.allowSlidePrev = true;
|
15 | swiper.allowSlideNext = true;
|
16 | const snapTranslate = -snapGrid[activeIndex];
|
17 | const diff = snapTranslate - swiper.getTranslate();
|
18 |
|
19 | if (activeIndex < loopedSlides) {
|
20 | newIndex = slides.length - loopedSlides * 3 + activeIndex;
|
21 | newIndex += loopedSlides;
|
22 | const slideChanged = swiper.slideTo(newIndex, 0, false, true);
|
23 |
|
24 | if (slideChanged && diff !== 0) {
|
25 | swiper.setTranslate((rtl ? -swiper.translate : swiper.translate) - diff);
|
26 | }
|
27 | } else if (activeIndex >= slides.length - loopedSlides) {
|
28 |
|
29 | newIndex = -slides.length + activeIndex + loopedSlides;
|
30 | newIndex += loopedSlides;
|
31 | const slideChanged = swiper.slideTo(newIndex, 0, false, true);
|
32 |
|
33 | if (slideChanged && diff !== 0) {
|
34 | swiper.setTranslate((rtl ? -swiper.translate : swiper.translate) - diff);
|
35 | }
|
36 | }
|
37 |
|
38 | swiper.allowSlidePrev = allowSlidePrev;
|
39 | swiper.allowSlideNext = allowSlideNext;
|
40 | swiper.emit('loopFix');
|
41 | } |
\ | No newline at end of file |