UNPKG

1.16 kBJavaScriptView Raw
1export default function setTranslate(translate, byController) {
2 const swiper = this;
3 const {
4 rtlTranslate: rtl,
5 params,
6 $wrapperEl,
7 wrapperEl,
8 progress
9 } = swiper;
10 let x = 0;
11 let y = 0;
12 const z = 0;
13
14 if (swiper.isHorizontal()) {
15 x = rtl ? -translate : translate;
16 } else {
17 y = translate;
18 }
19
20 if (params.roundLengths) {
21 x = Math.floor(x);
22 y = Math.floor(y);
23 }
24
25 if (params.cssMode) {
26 wrapperEl[swiper.isHorizontal() ? 'scrollLeft' : 'scrollTop'] = swiper.isHorizontal() ? -x : -y;
27 } else if (!params.virtualTranslate) {
28 $wrapperEl.transform(`translate3d(${x}px, ${y}px, ${z}px)`);
29 }
30
31 swiper.previousTranslate = swiper.translate;
32 swiper.translate = swiper.isHorizontal() ? x : y; // Check if we need to update progress
33
34 let newProgress;
35 const translatesDiff = swiper.maxTranslate() - swiper.minTranslate();
36
37 if (translatesDiff === 0) {
38 newProgress = 0;
39 } else {
40 newProgress = (translate - swiper.minTranslate()) / translatesDiff;
41 }
42
43 if (newProgress !== progress) {
44 swiper.updateProgress(translate);
45 }
46
47 swiper.emit('setTranslate', swiper.translate, byController);
48}
\No newline at end of file