@thinkpixellab-public/px-vue 3.0.89 → 3.0.91
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -38,11 +38,18 @@ export default {
|
|
|
38
38
|
// selector used to find children of the element that should slide during the transition
|
|
39
39
|
dragSelector: { type: String, default: '[data-drag]' },
|
|
40
40
|
|
|
41
|
+
// selector used to find drag elements in the dom that should animate in a reverse direction in vertical transitions
|
|
42
|
+
dragReverseSelector: { type: String, default: '[data-drag-reverse]' },
|
|
43
|
+
|
|
41
44
|
// if true, slide the parent element if no slideSelect children are found (false will result just fading)
|
|
42
45
|
dragElementFallback: { type: Boolean, default: true },
|
|
43
46
|
|
|
44
|
-
// 1 moves to the
|
|
47
|
+
// 1 moves the content to the left/up, -1 moves to the right/down
|
|
45
48
|
direction: { type: Number, default: 1 },
|
|
49
|
+
|
|
50
|
+
// vertical or horizontal
|
|
51
|
+
orientation: { type: String, default: 'horizontal' },
|
|
52
|
+
|
|
46
53
|
// TODO rtlAdjust: {type: Boolean, default: false }
|
|
47
54
|
|
|
48
55
|
duration: { type: Number, default: 1 },
|
|
@@ -82,29 +89,76 @@ export default {
|
|
|
82
89
|
return element.querySelectorAll(this.dragSelector);
|
|
83
90
|
},
|
|
84
91
|
|
|
92
|
+
slideElementsReverse(element) {
|
|
93
|
+
if (!element || !this.orientation == 'vertical') {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
return element.querySelectorAll(this.dragReverseSelector);
|
|
97
|
+
},
|
|
98
|
+
|
|
85
99
|
beforeEnter() {},
|
|
86
100
|
|
|
87
101
|
enter(element, done) {
|
|
88
|
-
|
|
102
|
+
const slideElements = this.slideElements(element);
|
|
103
|
+
|
|
89
104
|
if (slideElements?.length) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
105
|
+
const from = {};
|
|
106
|
+
const to = { ...this.tweenShared, onComplete: done };
|
|
107
|
+
|
|
108
|
+
if (this.orientation === 'vertical') {
|
|
109
|
+
from.y = this.directionAmount(this.direction * -1);
|
|
110
|
+
to.y = 0;
|
|
111
|
+
} else {
|
|
112
|
+
from.x = this.directionAmount(this.direction * -1);
|
|
113
|
+
to.x = 0;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
gsap.fromTo(slideElements, from, to);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (this.orientation === 'vertical') {
|
|
120
|
+
const slideElementsReverse = this.slideElementsReverse(element);
|
|
121
|
+
if (slideElementsReverse?.length) {
|
|
122
|
+
gsap.fromTo(
|
|
123
|
+
slideElementsReverse,
|
|
124
|
+
{ y: this.directionAmount(this.direction) },
|
|
125
|
+
{ y: 0, ...this.tweenShared }
|
|
126
|
+
);
|
|
127
|
+
}
|
|
97
128
|
}
|
|
98
129
|
},
|
|
99
130
|
leave(element, done) {
|
|
100
|
-
|
|
101
|
-
|
|
131
|
+
const slideElements = this.slideElements(element);
|
|
132
|
+
|
|
133
|
+
const to = {
|
|
134
|
+
...this.tweenShared,
|
|
135
|
+
onComplete: done,
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
if (this.orientation === 'vertical') {
|
|
139
|
+
to.y = this.directionAmount(this.direction, true);
|
|
140
|
+
} else {
|
|
141
|
+
to.x = this.directionAmount(this.direction, true);
|
|
142
|
+
}
|
|
143
|
+
|
|
102
144
|
if (slideElements?.length) {
|
|
103
|
-
gsap.to(slideElements,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
145
|
+
gsap.to(slideElements, to);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (this.orientation === 'vertical') {
|
|
149
|
+
const slideElementsReverse = this.slideElementsReverse(element);
|
|
150
|
+
console.log(`slideElementsReverse.length: ${slideElementsReverse.length}`);
|
|
151
|
+
|
|
152
|
+
if (slideElementsReverse?.length) {
|
|
153
|
+
const slideElementsReverse = this.slideElementsReverse(element);
|
|
154
|
+
|
|
155
|
+
const toReverse = {
|
|
156
|
+
...this.tweenShared,
|
|
157
|
+
y: this.directionAmount(this.direction * -1, true),
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
gsap.to(slideElementsReverse, toReverse);
|
|
161
|
+
}
|
|
108
162
|
}
|
|
109
163
|
},
|
|
110
164
|
},
|
package/components/PxSlides.vue
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
<px-slide-transition
|
|
13
13
|
:disable-animations="disableAnimations"
|
|
14
14
|
:direction="direction"
|
|
15
|
+
:orientation="orientation"
|
|
15
16
|
@before-leave="transitionStart"
|
|
16
17
|
@after-leave="transitionEnd"
|
|
17
18
|
@leave-cancelled="transitionEnd"
|
|
@@ -55,6 +56,9 @@ export default {
|
|
|
55
56
|
components: { PxSlideTransition, PxIcon },
|
|
56
57
|
|
|
57
58
|
props: {
|
|
59
|
+
// vertical or horizontal
|
|
60
|
+
orientation: { type: String, default: 'horizontal' },
|
|
61
|
+
|
|
58
62
|
// whether drag interaction is enabled
|
|
59
63
|
dragEnabled: { type: Boolean, default: true },
|
|
60
64
|
|
|
@@ -70,9 +74,13 @@ export default {
|
|
|
70
74
|
// selector used to find drag elements in the dom
|
|
71
75
|
dragSelector: { type: String, default: '[data-drag]' },
|
|
72
76
|
|
|
77
|
+
// selector used to find drag elements in the dom that should animate in a reverse direction in vertical transitions
|
|
78
|
+
dragReverseSelector: { type: String, default: '[data-drag-reverse]' },
|
|
79
|
+
|
|
73
80
|
// exclude from drag
|
|
74
81
|
dragExcludeSelector: { type: String, default: 'input, button, [data-no-drag]' },
|
|
75
82
|
|
|
83
|
+
// exclude from scroll
|
|
76
84
|
scrollExcludeSelector: { type: String, default: '[data-no-slidescroll]' },
|
|
77
85
|
|
|
78
86
|
// override default
|
|
@@ -88,6 +96,9 @@ export default {
|
|
|
88
96
|
lastInteractionType: null,
|
|
89
97
|
activeTransitions: 0,
|
|
90
98
|
scrollPreview: 0,
|
|
99
|
+
|
|
100
|
+
// true whenver the selected item is in an offset by dragging or a transition
|
|
101
|
+
hasOffset: false,
|
|
91
102
|
};
|
|
92
103
|
},
|
|
93
104
|
computed: {
|
|
@@ -129,6 +140,13 @@ export default {
|
|
|
129
140
|
},
|
|
130
141
|
},
|
|
131
142
|
watch: {
|
|
143
|
+
hasOffset(nv) {
|
|
144
|
+
if (nv) {
|
|
145
|
+
this.$emit('offset-start');
|
|
146
|
+
} else {
|
|
147
|
+
this.$emit('offset-end');
|
|
148
|
+
}
|
|
149
|
+
},
|
|
132
150
|
syncSelected(nv, ov) {
|
|
133
151
|
let newIndex = this.itemKeys.indexOf(nv);
|
|
134
152
|
let oldIndex = this.itemKeys.indexOf(ov);
|
|
@@ -179,7 +197,7 @@ export default {
|
|
|
179
197
|
}
|
|
180
198
|
|
|
181
199
|
this.drag = new Drag(this.$el, {
|
|
182
|
-
lock: 'x',
|
|
200
|
+
lock: this.orientation === 'horizontal' ? 'x' : 'y',
|
|
183
201
|
onStart: this.onDragStart,
|
|
184
202
|
onDrag: this.onDrag,
|
|
185
203
|
onEnd: this.onDragEnd,
|
|
@@ -198,6 +216,7 @@ export default {
|
|
|
198
216
|
transitionStart() {
|
|
199
217
|
if (!this.activeTransitions) {
|
|
200
218
|
this.$emit('transitions-start');
|
|
219
|
+
this.hasOffset = true;
|
|
201
220
|
}
|
|
202
221
|
this.activeTransitions++;
|
|
203
222
|
},
|
|
@@ -208,6 +227,7 @@ export default {
|
|
|
208
227
|
this.$emit('transitions-end', {
|
|
209
228
|
toIndex: this.itemKeys.indexOf(this.syncSelected),
|
|
210
229
|
});
|
|
230
|
+
this.hasOffset = false;
|
|
211
231
|
}
|
|
212
232
|
},
|
|
213
233
|
|
|
@@ -217,26 +237,51 @@ export default {
|
|
|
217
237
|
|
|
218
238
|
if (slide) {
|
|
219
239
|
this.dragElements = [...slide.querySelectorAll(this.dragSelector)];
|
|
240
|
+
this.dragElementsReverse = [...slide.querySelectorAll(this.dragReverseSelector)];
|
|
220
241
|
}
|
|
242
|
+
|
|
243
|
+
this.hasOffset = true;
|
|
221
244
|
},
|
|
222
245
|
|
|
223
246
|
onDrag(ev) {
|
|
224
|
-
if (this.dragElements?.length) {
|
|
247
|
+
if (this.dragElements?.length || this.dragElementsReverse?.length) {
|
|
225
248
|
if (gsap.isTweening(this.dragElements[0])) {
|
|
226
249
|
gsap.killTweensOf(this.dragElements);
|
|
227
250
|
}
|
|
228
|
-
|
|
251
|
+
|
|
252
|
+
if (gsap.isTweening(this.dragElementsReverse[0])) {
|
|
253
|
+
gsap.killTweensOf(this.dragElementsReverse);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (this.orientation === 'vertical') {
|
|
257
|
+
gsap.set(this.dragElements, { y: ev.startDelta.y });
|
|
258
|
+
gsap.set(this.dragElementsReverse, { y: -1 * ev.startDelta.y });
|
|
259
|
+
} else {
|
|
260
|
+
gsap.set(this.dragElements, { x: ev.startDelta.x });
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
this.hasOffset = true;
|
|
229
264
|
}
|
|
230
265
|
},
|
|
231
266
|
|
|
232
267
|
onDragEnd(ev) {
|
|
233
|
-
|
|
234
|
-
|
|
268
|
+
const delta = this.orientation === 'vertical' ? ev.delta.y : ev.delta.x;
|
|
269
|
+
if (Math.abs(delta) < 10) {
|
|
270
|
+
this.hasOffset = false;
|
|
271
|
+
|
|
272
|
+
// snap back
|
|
273
|
+
const to = {};
|
|
274
|
+
to[this.orientation === 'vertical' ? 'y' : 'x'] = 0;
|
|
275
|
+
gsap.to(this.dragElements, { ...to });
|
|
276
|
+
|
|
277
|
+
// snap back reverse elements (vertical only)
|
|
278
|
+
if (this.orientation === 'vertical') {
|
|
279
|
+
gsap.to(this.dragElementsReverse, { y: 0 });
|
|
280
|
+
}
|
|
235
281
|
} else {
|
|
236
282
|
this.lastInteractionType = 'drag';
|
|
237
283
|
this.$emit('drag-complete');
|
|
238
|
-
|
|
239
|
-
if (ev.delta.x > 0) {
|
|
284
|
+
if (delta > 0) {
|
|
240
285
|
this.previous();
|
|
241
286
|
} else {
|
|
242
287
|
this.next();
|