1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,122 +0,0 @@ |
1 |
-import $ from '../../utils/dom'; |
|
2 |
-import Support from '../../utils/support'; |
|
3 |
-import Utils from '../../utils/utils'; |
|
4 |
- |
|
5 |
-const Coverflow = { |
|
6 |
- setTranslate() { |
|
7 |
- const swiper = this; |
|
8 |
- const { |
|
9 |
- width: swiperWidth, height: swiperHeight, slides, $wrapperEl, slidesSizesGrid, |
|
10 |
- } = swiper; |
|
11 |
- const params = swiper.params.coverflowEffect; |
|
12 |
- const isHorizontal = swiper.isHorizontal(); |
|
13 |
- const transform = swiper.translate; |
|
14 |
- const center = isHorizontal ? -transform + (swiperWidth / 2) : -transform + (swiperHeight / 2); |
|
15 |
- const rotate = isHorizontal ? params.rotate : -params.rotate; |
|
16 |
- const translate = params.depth; |
|
17 |
- // Each slide offset from center |
|
18 |
- for (let i = 0, length = slides.length; i < length; i += 1) { |
|
19 |
- const $slideEl = slides.eq(i); |
|
20 |
- const slideSize = slidesSizesGrid[i]; |
|
21 |
- const slideOffset = $slideEl[0].swiperSlideOffset; |
|
22 |
- const offsetMultiplier = ((center - slideOffset - (slideSize / 2)) / slideSize) * params.modifier; |
|
23 |
- |
|
24 |
- let rotateY = isHorizontal ? rotate * offsetMultiplier : 0; |
|
25 |
- let rotateX = isHorizontal ? 0 : rotate * offsetMultiplier; |
|
26 |
- // var rotateZ = 0 |
|
27 |
- let translateZ = -translate * Math.abs(offsetMultiplier); |
|
28 |
- |
|
29 |
- let stretch = params.stretch; |
|
30 |
- // Allow percentage to make a relative stretch for responsive sliders |
|
31 |
- if (typeof stretch === 'string' && stretch.indexOf('%') !== -1) { |
|
32 |
- stretch = ((parseFloat(params.stretch) / 100) * slideSize); |
|
33 |
- } |
|
34 |
- let translateY = isHorizontal ? 0 : stretch * (offsetMultiplier); |
|
35 |
- let translateX = isHorizontal ? stretch * (offsetMultiplier) : 0; |
|
36 |
- |
|
37 |
- // Fix for ultra small values |
|
38 |
- if (Math.abs(translateX) < 0.001) translateX = 0; |
|
39 |
- if (Math.abs(translateY) < 0.001) translateY = 0; |
|
40 |
- if (Math.abs(translateZ) < 0.001) translateZ = 0; |
|
41 |
- if (Math.abs(rotateY) < 0.001) rotateY = 0; |
|
42 |
- if (Math.abs(rotateX) < 0.001) rotateX = 0; |
|
43 |
- |
|
44 |
- const slideTransform = `translate3d(${translateX}px,${translateY}px,${translateZ}px) rotateX(${rotateX}deg) rotateY(${rotateY}deg)`; |
|
45 |
- |
|
46 |
- $slideEl.transform(slideTransform); |
|
47 |
- $slideEl[0].style.zIndex = -Math.abs(Math.round(offsetMultiplier)) + 1; |
|
48 |
- if (params.slideShadows) { |
|
49 |
- // Set shadows |
|
50 |
- let $shadowBeforeEl = isHorizontal ? $slideEl.find('.swiper-slide-shadow-left') : $slideEl.find('.swiper-slide-shadow-top'); |
|
51 |
- let $shadowAfterEl = isHorizontal ? $slideEl.find('.swiper-slide-shadow-right') : $slideEl.find('.swiper-slide-shadow-bottom'); |
|
52 |
- if ($shadowBeforeEl.length === 0) { |
|
53 |
- $shadowBeforeEl = $(`<div class="swiper-slide-shadow-${isHorizontal ? 'left' : 'top'}"></div>`); |
|
54 |
- $slideEl.append($shadowBeforeEl); |
|
55 |
- } |
|
56 |
- if ($shadowAfterEl.length === 0) { |
|
57 |
- $shadowAfterEl = $(`<div class="swiper-slide-shadow-${isHorizontal ? 'right' : 'bottom'}"></div>`); |
|
58 |
- $slideEl.append($shadowAfterEl); |
|
59 |
- } |
|
60 |
- if ($shadowBeforeEl.length) $shadowBeforeEl[0].style.opacity = offsetMultiplier > 0 ? offsetMultiplier : 0; |
|
61 |
- if ($shadowAfterEl.length) $shadowAfterEl[0].style.opacity = (-offsetMultiplier) > 0 ? -offsetMultiplier : 0; |
|
62 |
- } |
|
63 |
- } |
|
64 |
- |
|
65 |
- // Set correct perspective for IE10 |
|
66 |
- if (Support.pointerEvents || Support.prefixedPointerEvents) { |
|
67 |
- const ws = $wrapperEl[0].style; |
|
68 |
- ws.perspectiveOrigin = `${center}px 50%`; |
|
69 |
- } |
|
70 |
- }, |
|
71 |
- setTransition(duration) { |
|
72 |
- const swiper = this; |
|
73 |
- swiper.slides |
|
74 |
- .transition(duration) |
|
75 |
- .find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left') |
|
76 |
- .transition(duration); |
|
77 |
- }, |
|
78 |
-}; |
|
79 |
- |
|
80 |
-export default { |
|
81 |
- name: 'effect-coverflow', |
|
82 |
- params: { |
|
83 |
- coverflowEffect: { |
|
84 |
- rotate: 50, |
|
85 |
- stretch: 0, |
|
86 |
- depth: 100, |
|
87 |
- modifier: 1, |
|
88 |
- slideShadows: true, |
|
89 |
- }, |
|
90 |
- }, |
|
91 |
- create() { |
|
92 |
- const swiper = this; |
|
93 |
- Utils.extend(swiper, { |
|
94 |
- coverflowEffect: { |
|
95 |
- setTranslate: Coverflow.setTranslate.bind(swiper), |
|
96 |
- setTransition: Coverflow.setTransition.bind(swiper), |
|
97 |
- }, |
|
98 |
- }); |
|
99 |
- }, |
|
100 |
- on: { |
|
101 |
- beforeInit() { |
|
102 |
- const swiper = this; |
|
103 |
- if (swiper.params.effect !== 'coverflow') return; |
|
104 |
- |
|
105 |
- swiper.classNames.push(`${swiper.params.containerModifierClass}coverflow`); |
|
106 |
- swiper.classNames.push(`${swiper.params.containerModifierClass}3d`); |
|
107 |
- |
|
108 |
- swiper.params.watchSlidesProgress = true; |
|
109 |
- swiper.originalParams.watchSlidesProgress = true; |
|
110 |
- }, |
|
111 |
- setTranslate() { |
|
112 |
- const swiper = this; |
|
113 |
- if (swiper.params.effect !== 'coverflow') return; |
|
114 |
- swiper.coverflowEffect.setTranslate(); |
|
115 |
- }, |
|
116 |
- setTransition(duration) { |
|
117 |
- const swiper = this; |
|
118 |
- if (swiper.params.effect !== 'coverflow') return; |
|
119 |
- swiper.coverflowEffect.setTransition(duration); |
|
120 |
- }, |
|
121 |
- }, |
|
122 |
-}; |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,122 @@ |
1 |
+import $ from '../../utils/dom'; |
|
2 |
+import Support from '../../utils/support'; |
|
3 |
+import Utils from '../../utils/utils'; |
|
4 |
+ |
|
5 |
+const Coverflow = { |
|
6 |
+ setTranslate() { |
|
7 |
+ const swiper = this; |
|
8 |
+ const { |
|
9 |
+ width: swiperWidth, height: swiperHeight, slides, $wrapperEl, slidesSizesGrid, |
|
10 |
+ } = swiper; |
|
11 |
+ const params = swiper.params.coverflowEffect; |
|
12 |
+ const isHorizontal = swiper.isHorizontal(); |
|
13 |
+ const transform = swiper.translate; |
|
14 |
+ const center = isHorizontal ? -transform + (swiperWidth / 2) : -transform + (swiperHeight / 2); |
|
15 |
+ const rotate = isHorizontal ? params.rotate : -params.rotate; |
|
16 |
+ const translate = params.depth; |
|
17 |
+ // Each slide offset from center |
|
18 |
+ for (let i = 0, length = slides.length; i < length; i += 1) { |
|
19 |
+ const $slideEl = slides.eq(i); |
|
20 |
+ const slideSize = slidesSizesGrid[i]; |
|
21 |
+ const slideOffset = $slideEl[0].swiperSlideOffset; |
|
22 |
+ const offsetMultiplier = ((center - slideOffset - (slideSize / 2)) / slideSize) * params.modifier; |
|
23 |
+ |
|
24 |
+ let rotateY = isHorizontal ? rotate * offsetMultiplier : 0; |
|
25 |
+ let rotateX = isHorizontal ? 0 : rotate * offsetMultiplier; |
|
26 |
+ // var rotateZ = 0 |
|
27 |
+ let translateZ = -translate * Math.abs(offsetMultiplier); |
|
28 |
+ |
|
29 |
+ let stretch = params.stretch; |
|
30 |
+ // Allow percentage to make a relative stretch for responsive sliders |
|
31 |
+ if (typeof stretch === 'string' && stretch.indexOf('%') !== -1) { |
|
32 |
+ stretch = ((parseFloat(params.stretch) / 100) * slideSize); |
|
33 |
+ } |
|
34 |
+ let translateY = isHorizontal ? 0 : stretch * (offsetMultiplier); |
|
35 |
+ let translateX = isHorizontal ? stretch * (offsetMultiplier) : 0; |
|
36 |
+ |
|
37 |
+ // Fix for ultra small values |
|
38 |
+ if (Math.abs(translateX) < 0.001) translateX = 0; |
|
39 |
+ if (Math.abs(translateY) < 0.001) translateY = 0; |
|
40 |
+ if (Math.abs(translateZ) < 0.001) translateZ = 0; |
|
41 |
+ if (Math.abs(rotateY) < 0.001) rotateY = 0; |
|
42 |
+ if (Math.abs(rotateX) < 0.001) rotateX = 0; |
|
43 |
+ |
|
44 |
+ const slideTransform = `translate3d(${translateX}px,${translateY}px,${translateZ}px) rotateX(${rotateX}deg) rotateY(${rotateY}deg)`; |
|
45 |
+ |
|
46 |
+ $slideEl.transform(slideTransform); |
|
47 |
+ $slideEl[0].style.zIndex = -Math.abs(Math.round(offsetMultiplier)) + 1; |
|
48 |
+ if (params.slideShadows) { |
|
49 |
+ // Set shadows |
|
50 |
+ let $shadowBeforeEl = isHorizontal ? $slideEl.find('.swiper-slide-shadow-left') : $slideEl.find('.swiper-slide-shadow-top'); |
|
51 |
+ let $shadowAfterEl = isHorizontal ? $slideEl.find('.swiper-slide-shadow-right') : $slideEl.find('.swiper-slide-shadow-bottom'); |
|
52 |
+ if ($shadowBeforeEl.length === 0) { |
|
53 |
+ $shadowBeforeEl = $(`<div class="swiper-slide-shadow-${isHorizontal ? 'left' : 'top'}"></div>`); |
|
54 |
+ $slideEl.append($shadowBeforeEl); |
|
55 |
+ } |
|
56 |
+ if ($shadowAfterEl.length === 0) { |
|
57 |
+ $shadowAfterEl = $(`<div class="swiper-slide-shadow-${isHorizontal ? 'right' : 'bottom'}"></div>`); |
|
58 |
+ $slideEl.append($shadowAfterEl); |
|
59 |
+ } |
|
60 |
+ if ($shadowBeforeEl.length) $shadowBeforeEl[0].style.opacity = offsetMultiplier > 0 ? offsetMultiplier : 0; |
|
61 |
+ if ($shadowAfterEl.length) $shadowAfterEl[0].style.opacity = (-offsetMultiplier) > 0 ? -offsetMultiplier : 0; |
|
62 |
+ } |
|
63 |
+ } |
|
64 |
+ |
|
65 |
+ // Set correct perspective for IE10 |
|
66 |
+ if (Support.pointerEvents || Support.prefixedPointerEvents) { |
|
67 |
+ const ws = $wrapperEl[0].style; |
|
68 |
+ ws.perspectiveOrigin = `${center}px 50%`; |
|
69 |
+ } |
|
70 |
+ }, |
|
71 |
+ setTransition(duration) { |
|
72 |
+ const swiper = this; |
|
73 |
+ swiper.slides |
|
74 |
+ .transition(duration) |
|
75 |
+ .find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left') |
|
76 |
+ .transition(duration); |
|
77 |
+ }, |
|
78 |
+}; |
|
79 |
+ |
|
80 |
+export default { |
|
81 |
+ name: 'effect-coverflow', |
|
82 |
+ params: { |
|
83 |
+ coverflowEffect: { |
|
84 |
+ rotate: 50, |
|
85 |
+ stretch: 0, |
|
86 |
+ depth: 100, |
|
87 |
+ modifier: 1, |
|
88 |
+ slideShadows: true, |
|
89 |
+ }, |
|
90 |
+ }, |
|
91 |
+ create() { |
|
92 |
+ const swiper = this; |
|
93 |
+ Utils.extend(swiper, { |
|
94 |
+ coverflowEffect: { |
|
95 |
+ setTranslate: Coverflow.setTranslate.bind(swiper), |
|
96 |
+ setTransition: Coverflow.setTransition.bind(swiper), |
|
97 |
+ }, |
|
98 |
+ }); |
|
99 |
+ }, |
|
100 |
+ on: { |
|
101 |
+ beforeInit() { |
|
102 |
+ const swiper = this; |
|
103 |
+ if (swiper.params.effect !== 'coverflow') return; |
|
104 |
+ |
|
105 |
+ swiper.classNames.push(`${swiper.params.containerModifierClass}coverflow`); |
|
106 |
+ swiper.classNames.push(`${swiper.params.containerModifierClass}3d`); |
|
107 |
+ |
|
108 |
+ swiper.params.watchSlidesProgress = true; |
|
109 |
+ swiper.originalParams.watchSlidesProgress = true; |
|
110 |
+ }, |
|
111 |
+ setTranslate() { |
|
112 |
+ const swiper = this; |
|
113 |
+ if (swiper.params.effect !== 'coverflow') return; |
|
114 |
+ swiper.coverflowEffect.setTranslate(); |
|
115 |
+ }, |
|
116 |
+ setTransition(duration) { |
|
117 |
+ const swiper = this; |
|
118 |
+ if (swiper.params.effect !== 'coverflow') return; |
|
119 |
+ swiper.coverflowEffect.setTransition(duration); |
|
120 |
+ }, |
|
121 |
+ }, |
|
122 |
+}; |