UNPKG

1.23 kBJavaScriptView Raw
1export default function updateProgress(translate) {
2 const swiper = this;
3
4 if (typeof translate === 'undefined') {
5 const multiplier = swiper.rtlTranslate ? -1 : 1; // eslint-disable-next-line
6
7 translate = swiper && swiper.translate && swiper.translate * multiplier || 0;
8 }
9
10 const params = swiper.params;
11 const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
12 let {
13 progress,
14 isBeginning,
15 isEnd
16 } = swiper;
17 const wasBeginning = isBeginning;
18 const wasEnd = isEnd;
19
20 if (translatesDiff === 0) {
21 progress = 0;
22 isBeginning = true;
23 isEnd = true;
24 } else {
25 progress = (translate - swiper.minTranslate()) / translatesDiff;
26 isBeginning = progress <= 0;
27 isEnd = progress >= 1;
28 }
29
30 Object.assign(swiper, {
31 progress,
32 isBeginning,
33 isEnd
34 });
35 if (params.watchSlidesProgress || params.centeredSlides && params.autoHeight) swiper.updateSlidesProgress(translate);
36
37 if (isBeginning && !wasBeginning) {
38 swiper.emit('reachBeginning toEdge');
39 }
40
41 if (isEnd && !wasEnd) {
42 swiper.emit('reachEnd toEdge');
43 }
44
45 if (wasBeginning && !isBeginning || wasEnd && !isEnd) {
46 swiper.emit('fromEdge');
47 }
48
49 swiper.emit('progress', progress);
50}
\No newline at end of file