1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,121 +0,0 @@ |
1 |
-function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } |
|
2 |
- |
|
3 |
-import $ from '../../utils/dom'; |
|
4 |
-import { bindModuleMethods } from '../../utils/utils'; |
|
5 |
-var Parallax = { |
|
6 |
- setTransform: function setTransform(el, progress) { |
|
7 |
- var swiper = this; |
|
8 |
- var rtl = swiper.rtl; |
|
9 |
- var $el = $(el); |
|
10 |
- var rtlFactor = rtl ? -1 : 1; |
|
11 |
- var p = $el.attr('data-swiper-parallax') || '0'; |
|
12 |
- var x = $el.attr('data-swiper-parallax-x'); |
|
13 |
- var y = $el.attr('data-swiper-parallax-y'); |
|
14 |
- var scale = $el.attr('data-swiper-parallax-scale'); |
|
15 |
- var opacity = $el.attr('data-swiper-parallax-opacity'); |
|
16 |
- |
|
17 |
- if (x || y) { |
|
18 |
- x = x || '0'; |
|
19 |
- y = y || '0'; |
|
20 |
- } else if (swiper.isHorizontal()) { |
|
21 |
- x = p; |
|
22 |
- y = '0'; |
|
23 |
- } else { |
|
24 |
- y = p; |
|
25 |
- x = '0'; |
|
26 |
- } |
|
27 |
- |
|
28 |
- if (x.indexOf('%') >= 0) { |
|
29 |
- x = parseInt(x, 10) * progress * rtlFactor + "%"; |
|
30 |
- } else { |
|
31 |
- x = x * progress * rtlFactor + "px"; |
|
32 |
- } |
|
33 |
- |
|
34 |
- if (y.indexOf('%') >= 0) { |
|
35 |
- y = parseInt(y, 10) * progress + "%"; |
|
36 |
- } else { |
|
37 |
- y = y * progress + "px"; |
|
38 |
- } |
|
39 |
- |
|
40 |
- if (typeof opacity !== 'undefined' && opacity !== null) { |
|
41 |
- var currentOpacity = opacity - (opacity - 1) * (1 - Math.abs(progress)); |
|
42 |
- $el[0].style.opacity = currentOpacity; |
|
43 |
- } |
|
44 |
- |
|
45 |
- if (typeof scale === 'undefined' || scale === null) { |
|
46 |
- $el.transform("translate3d(" + x + ", " + y + ", 0px)"); |
|
47 |
- } else { |
|
48 |
- var currentScale = scale - (scale - 1) * (1 - Math.abs(progress)); |
|
49 |
- $el.transform("translate3d(" + x + ", " + y + ", 0px) scale(" + currentScale + ")"); |
|
50 |
- } |
|
51 |
- }, |
|
52 |
- setTranslate: function setTranslate() { |
|
53 |
- var swiper = this; |
|
54 |
- var $el = swiper.$el, |
|
55 |
- slides = swiper.slides, |
|
56 |
- progress = swiper.progress, |
|
57 |
- snapGrid = swiper.snapGrid; |
|
58 |
- $el.children('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y], [data-swiper-parallax-opacity], [data-swiper-parallax-scale]').each(function (el) { |
|
59 |
- swiper.parallax.setTransform(el, progress); |
|
60 |
- }); |
|
61 |
- slides.each(function (slideEl, slideIndex) { |
|
62 |
- var slideProgress = slideEl.progress; |
|
63 |
- |
|
64 |
- if (swiper.params.slidesPerGroup > 1 && swiper.params.slidesPerView !== 'auto') { |
|
65 |
- slideProgress += Math.ceil(slideIndex / 2) - progress * (snapGrid.length - 1); |
|
66 |
- } |
|
67 |
- |
|
68 |
- slideProgress = Math.min(Math.max(slideProgress, -1), 1); |
|
69 |
- $(slideEl).find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y], [data-swiper-parallax-opacity], [data-swiper-parallax-scale]').each(function (el) { |
|
70 |
- swiper.parallax.setTransform(el, slideProgress); |
|
71 |
- }); |
|
72 |
- }); |
|
73 |
- }, |
|
74 |
- setTransition: function setTransition(duration) { |
|
75 |
- if (duration === void 0) { |
|
76 |
- duration = this.params.speed; |
|
77 |
- } |
|
78 |
- |
|
79 |
- var swiper = this; |
|
80 |
- var $el = swiper.$el; |
|
81 |
- $el.find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y], [data-swiper-parallax-opacity], [data-swiper-parallax-scale]').each(function (parallaxEl) { |
|
82 |
- var $parallaxEl = $(parallaxEl); |
|
83 |
- var parallaxDuration = parseInt($parallaxEl.attr('data-swiper-parallax-duration'), 10) || duration; |
|
84 |
- if (duration === 0) parallaxDuration = 0; |
|
85 |
- $parallaxEl.transition(parallaxDuration); |
|
86 |
- }); |
|
87 |
- } |
|
88 |
-}; |
|
89 |
-export default { |
|
90 |
- name: 'parallax', |
|
91 |
- params: { |
|
92 |
- parallax: { |
|
93 |
- enabled: false |
|
94 |
- } |
|
95 |
- }, |
|
96 |
- create: function create() { |
|
97 |
- var swiper = this; |
|
98 |
- bindModuleMethods(swiper, { |
|
99 |
- parallax: _extends({}, Parallax) |
|
100 |
- }); |
|
101 |
- }, |
|
102 |
- on: { |
|
103 |
- beforeInit: function beforeInit(swiper) { |
|
104 |
- if (!swiper.params.parallax.enabled) return; |
|
105 |
- swiper.params.watchSlidesProgress = true; |
|
106 |
- swiper.originalParams.watchSlidesProgress = true; |
|
107 |
- }, |
|
108 |
- init: function init(swiper) { |
|
109 |
- if (!swiper.params.parallax.enabled) return; |
|
110 |
- swiper.parallax.setTranslate(); |
|
111 |
- }, |
|
112 |
- setTranslate: function setTranslate(swiper) { |
|
113 |
- if (!swiper.params.parallax.enabled) return; |
|
114 |
- swiper.parallax.setTranslate(); |
|
115 |
- }, |
|
116 |
- setTransition: function setTransition(swiper, duration) { |
|
117 |
- if (!swiper.params.parallax.enabled) return; |
|
118 |
- swiper.parallax.setTransition(duration); |
|
119 |
- } |
|
120 |
- } |
|
121 |
-}; |
|
122 | 0 |
\ No newline at end of file |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,121 @@ |
1 |
+function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } |
|
2 |
+ |
|
3 |
+import $ from '../../utils/dom'; |
|
4 |
+import { bindModuleMethods } from '../../utils/utils'; |
|
5 |
+var Parallax = { |
|
6 |
+ setTransform: function setTransform(el, progress) { |
|
7 |
+ var swiper = this; |
|
8 |
+ var rtl = swiper.rtl; |
|
9 |
+ var $el = $(el); |
|
10 |
+ var rtlFactor = rtl ? -1 : 1; |
|
11 |
+ var p = $el.attr('data-swiper-parallax') || '0'; |
|
12 |
+ var x = $el.attr('data-swiper-parallax-x'); |
|
13 |
+ var y = $el.attr('data-swiper-parallax-y'); |
|
14 |
+ var scale = $el.attr('data-swiper-parallax-scale'); |
|
15 |
+ var opacity = $el.attr('data-swiper-parallax-opacity'); |
|
16 |
+ |
|
17 |
+ if (x || y) { |
|
18 |
+ x = x || '0'; |
|
19 |
+ y = y || '0'; |
|
20 |
+ } else if (swiper.isHorizontal()) { |
|
21 |
+ x = p; |
|
22 |
+ y = '0'; |
|
23 |
+ } else { |
|
24 |
+ y = p; |
|
25 |
+ x = '0'; |
|
26 |
+ } |
|
27 |
+ |
|
28 |
+ if (x.indexOf('%') >= 0) { |
|
29 |
+ x = parseInt(x, 10) * progress * rtlFactor + "%"; |
|
30 |
+ } else { |
|
31 |
+ x = x * progress * rtlFactor + "px"; |
|
32 |
+ } |
|
33 |
+ |
|
34 |
+ if (y.indexOf('%') >= 0) { |
|
35 |
+ y = parseInt(y, 10) * progress + "%"; |
|
36 |
+ } else { |
|
37 |
+ y = y * progress + "px"; |
|
38 |
+ } |
|
39 |
+ |
|
40 |
+ if (typeof opacity !== 'undefined' && opacity !== null) { |
|
41 |
+ var currentOpacity = opacity - (opacity - 1) * (1 - Math.abs(progress)); |
|
42 |
+ $el[0].style.opacity = currentOpacity; |
|
43 |
+ } |
|
44 |
+ |
|
45 |
+ if (typeof scale === 'undefined' || scale === null) { |
|
46 |
+ $el.transform("translate3d(" + x + ", " + y + ", 0px)"); |
|
47 |
+ } else { |
|
48 |
+ var currentScale = scale - (scale - 1) * (1 - Math.abs(progress)); |
|
49 |
+ $el.transform("translate3d(" + x + ", " + y + ", 0px) scale(" + currentScale + ")"); |
|
50 |
+ } |
|
51 |
+ }, |
|
52 |
+ setTranslate: function setTranslate() { |
|
53 |
+ var swiper = this; |
|
54 |
+ var $el = swiper.$el, |
|
55 |
+ slides = swiper.slides, |
|
56 |
+ progress = swiper.progress, |
|
57 |
+ snapGrid = swiper.snapGrid; |
|
58 |
+ $el.children('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y], [data-swiper-parallax-opacity], [data-swiper-parallax-scale]').each(function (el) { |
|
59 |
+ swiper.parallax.setTransform(el, progress); |
|
60 |
+ }); |
|
61 |
+ slides.each(function (slideEl, slideIndex) { |
|
62 |
+ var slideProgress = slideEl.progress; |
|
63 |
+ |
|
64 |
+ if (swiper.params.slidesPerGroup > 1 && swiper.params.slidesPerView !== 'auto') { |
|
65 |
+ slideProgress += Math.ceil(slideIndex / 2) - progress * (snapGrid.length - 1); |
|
66 |
+ } |
|
67 |
+ |
|
68 |
+ slideProgress = Math.min(Math.max(slideProgress, -1), 1); |
|
69 |
+ $(slideEl).find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y], [data-swiper-parallax-opacity], [data-swiper-parallax-scale]').each(function (el) { |
|
70 |
+ swiper.parallax.setTransform(el, slideProgress); |
|
71 |
+ }); |
|
72 |
+ }); |
|
73 |
+ }, |
|
74 |
+ setTransition: function setTransition(duration) { |
|
75 |
+ if (duration === void 0) { |
|
76 |
+ duration = this.params.speed; |
|
77 |
+ } |
|
78 |
+ |
|
79 |
+ var swiper = this; |
|
80 |
+ var $el = swiper.$el; |
|
81 |
+ $el.find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y], [data-swiper-parallax-opacity], [data-swiper-parallax-scale]').each(function (parallaxEl) { |
|
82 |
+ var $parallaxEl = $(parallaxEl); |
|
83 |
+ var parallaxDuration = parseInt($parallaxEl.attr('data-swiper-parallax-duration'), 10) || duration; |
|
84 |
+ if (duration === 0) parallaxDuration = 0; |
|
85 |
+ $parallaxEl.transition(parallaxDuration); |
|
86 |
+ }); |
|
87 |
+ } |
|
88 |
+}; |
|
89 |
+export default { |
|
90 |
+ name: 'parallax', |
|
91 |
+ params: { |
|
92 |
+ parallax: { |
|
93 |
+ enabled: false |
|
94 |
+ } |
|
95 |
+ }, |
|
96 |
+ create: function create() { |
|
97 |
+ var swiper = this; |
|
98 |
+ bindModuleMethods(swiper, { |
|
99 |
+ parallax: _extends({}, Parallax) |
|
100 |
+ }); |
|
101 |
+ }, |
|
102 |
+ on: { |
|
103 |
+ beforeInit: function beforeInit(swiper) { |
|
104 |
+ if (!swiper.params.parallax.enabled) return; |
|
105 |
+ swiper.params.watchSlidesProgress = true; |
|
106 |
+ swiper.originalParams.watchSlidesProgress = true; |
|
107 |
+ }, |
|
108 |
+ init: function init(swiper) { |
|
109 |
+ if (!swiper.params.parallax.enabled) return; |
|
110 |
+ swiper.parallax.setTranslate(); |
|
111 |
+ }, |
|
112 |
+ setTranslate: function setTranslate(swiper) { |
|
113 |
+ if (!swiper.params.parallax.enabled) return; |
|
114 |
+ swiper.parallax.setTranslate(); |
|
115 |
+ }, |
|
116 |
+ setTransition: function setTransition(swiper, duration) { |
|
117 |
+ if (!swiper.params.parallax.enabled) return; |
|
118 |
+ swiper.parallax.setTransition(duration); |
|
119 |
+ } |
|
120 |
+ } |
|
121 |
+}; |
|
0 | 122 |
\ No newline at end of file |