rytm-webflow 2.0.7 → 2.0.8
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.
- package/package.json +1 -1
- package/scripts/aswap/WebflowView.js +286 -0
- package/scripts/index.js +2 -0
package/package.json
CHANGED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import ScrollMagic from 'scrollmagic';
|
|
2
|
+
import gsap from 'gsap';
|
|
3
|
+
import View from './View';
|
|
4
|
+
import scrollController from './../showup/ScrollController';
|
|
5
|
+
import { getWebflowAnimationProps, parseProps } from './../lib/dataTweenParser';
|
|
6
|
+
import { getScrollMagicSceneProps } from './../lib/dataScrollMagicParser';
|
|
7
|
+
|
|
8
|
+
// data-webview-... (aswap show / hide)
|
|
9
|
+
const DATA_ATTR_WEBVIEW_INIT = "webview-initial";
|
|
10
|
+
const DATA_ATTR_WEBVIEW_SHOW = "webview-show";
|
|
11
|
+
const DATA_ATTR_WEBVIEW_HIDE = "webview-hide";
|
|
12
|
+
// data-webscroll-... (scroll magic)
|
|
13
|
+
const DATA_ATTR_WEBSCROLL_INIT = "webscroll-initial";
|
|
14
|
+
const DATA_ATTR_WEBSCROLL_SHOW = "webscroll-show";
|
|
15
|
+
const DATA_ATTR_WEBSCROLL_HIDE = "webscroll-hide";
|
|
16
|
+
// data-stagger-... (stagger - lists)
|
|
17
|
+
const DATA_ATTR_STAGGER_INIT = "stagger-initial";
|
|
18
|
+
const DATA_ATTR_STAGGER_SHOW = "stagger-show";
|
|
19
|
+
const DATA_ATTR_STAGGER_HIDE = "stagger-hide";
|
|
20
|
+
const DATA_ATTR_SETUP = "webset";
|
|
21
|
+
|
|
22
|
+
class WebflowView extends View {
|
|
23
|
+
|
|
24
|
+
constructor(id) {
|
|
25
|
+
super(id);
|
|
26
|
+
this.scenes = [];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* prepare (before show)
|
|
30
|
+
**/
|
|
31
|
+
prepare(container) {
|
|
32
|
+
super.prepare(container);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* animate in (show)
|
|
36
|
+
**/
|
|
37
|
+
show(container) {
|
|
38
|
+
super.show(container);
|
|
39
|
+
this.container = container;
|
|
40
|
+
// show Aswap webviews
|
|
41
|
+
this.webViewsShow();
|
|
42
|
+
// show stagger elements
|
|
43
|
+
this.staggerShow();
|
|
44
|
+
// build scrollmagic scenes
|
|
45
|
+
this.buildScrollmagicScenes();
|
|
46
|
+
// add event listeners
|
|
47
|
+
this.addEventListeners();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* animate out (hide)
|
|
51
|
+
**/
|
|
52
|
+
hide(container) {
|
|
53
|
+
super.hide(container);
|
|
54
|
+
// hide Aswap webviews
|
|
55
|
+
this.webViewsHide();
|
|
56
|
+
// hide stagger elements
|
|
57
|
+
this.staggerHide();
|
|
58
|
+
// hide scrollmagic scenes
|
|
59
|
+
this.hideScrollmagicScenes();
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* animate out (hide)
|
|
63
|
+
**/
|
|
64
|
+
hidden(container) {
|
|
65
|
+
super.hidden(container);
|
|
66
|
+
this.removeEventListeners();
|
|
67
|
+
this.destroyScenes();
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* ##################
|
|
71
|
+
* ### DOM events ###
|
|
72
|
+
* ##################
|
|
73
|
+
*/
|
|
74
|
+
/**
|
|
75
|
+
* Class event handlers
|
|
76
|
+
*/
|
|
77
|
+
handleEvent(e) {
|
|
78
|
+
switch (e.type) {
|
|
79
|
+
case 'resize':
|
|
80
|
+
this.onWindowUpdate(e);
|
|
81
|
+
break;
|
|
82
|
+
case 'DOMContentLoaded':
|
|
83
|
+
this.onWindowUpdate(e);
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Add event listeners
|
|
89
|
+
*/
|
|
90
|
+
addEventListeners() {
|
|
91
|
+
window.addEventListener('resize', this);
|
|
92
|
+
document.addEventListener('DOMContentLoaded', this);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Remove event listeners
|
|
96
|
+
*/
|
|
97
|
+
removeEventListeners() {
|
|
98
|
+
window.removeEventListener('resize', this);
|
|
99
|
+
document.removeEventListener('DOMContentLoaded', this);
|
|
100
|
+
}
|
|
101
|
+
onWindowUpdate(e) {
|
|
102
|
+
if (this.scenes.length > 0) {
|
|
103
|
+
scrollController.refresh();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* ############
|
|
108
|
+
* ### SHOW ###
|
|
109
|
+
* ############
|
|
110
|
+
*/
|
|
111
|
+
// ### ASwap Show / Hide ###
|
|
112
|
+
// show webviews
|
|
113
|
+
webViewsShow() {
|
|
114
|
+
if (!this.container) {
|
|
115
|
+
console.warn("Unknown container", this);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const list = [...this.container.querySelectorAll('*[data-' + DATA_ATTR_WEBVIEW_SHOW + ']')];
|
|
119
|
+
list.forEach(this.webViewElementShow.bind(this));
|
|
120
|
+
}
|
|
121
|
+
// showe webview element
|
|
122
|
+
webViewElementShow(el, index) {
|
|
123
|
+
const propsInitial = this.getTweenProps(el, DATA_ATTR_WEBVIEW_INIT);
|
|
124
|
+
const propsShow = this.getTweenProps(el, DATA_ATTR_WEBVIEW_SHOW);
|
|
125
|
+
if (propsInitial && propsShow) {
|
|
126
|
+
gsap.killTweensOf(el);
|
|
127
|
+
gsap.set(el, {...propsInitial.tween});
|
|
128
|
+
gsap.to(el, {duration: propsShow.time, ...propsShow.tween});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// ### Stagger ###
|
|
132
|
+
// Stagger (lists) show
|
|
133
|
+
staggerShow() {
|
|
134
|
+
if (!this.container) {
|
|
135
|
+
console.warn("Unknown container", this);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const list = [...this.container.querySelectorAll('*[data-' + DATA_ATTR_STAGGER_SHOW + ']')];
|
|
139
|
+
list.forEach(this.staggerListShow.bind(this));
|
|
140
|
+
}
|
|
141
|
+
staggerListShow(el, index) {
|
|
142
|
+
const { selector } = parseProps(el.dataset[DATA_ATTR_SETUP]);
|
|
143
|
+
if (!selector) {
|
|
144
|
+
console.warn("Unknown selector for webflow stagger", el);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const items = [...el.querySelectorAll(selector)];
|
|
148
|
+
const propsInit = this.getTweenProps(el, DATA_ATTR_STAGGER_INIT);
|
|
149
|
+
const propsShow = this.getTweenProps(el, DATA_ATTR_STAGGER_SHOW);
|
|
150
|
+
if (items.length && propsInit && propsShow) {
|
|
151
|
+
gsap.killTweensOf(items);
|
|
152
|
+
gsap.set(items, {...propsInit.tween});
|
|
153
|
+
gsap.to(items, {duration: propsShow.time, ...propsShow.tween});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// ### ScrollMagic ###
|
|
157
|
+
/**
|
|
158
|
+
* Build scenes for scrollmagic
|
|
159
|
+
*/
|
|
160
|
+
buildScrollmagicScenes() {
|
|
161
|
+
if (!this.container) {
|
|
162
|
+
console.warn("Unknown container", this);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const list = [...this.container.querySelectorAll('*[data-' + DATA_ATTR_WEBSCROLL_SHOW + ']')];
|
|
166
|
+
list.forEach(this.buildScrollmagicScene.bind(this));
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Build scroll magic scene
|
|
170
|
+
* @param {DOM} el
|
|
171
|
+
* @param {Int} index
|
|
172
|
+
*/
|
|
173
|
+
buildScrollmagicScene(el, index) {
|
|
174
|
+
const propsInitial = this.getTweenProps(el, DATA_ATTR_WEBSCROLL_INIT);
|
|
175
|
+
const propsShow = this.getTweenProps(el, DATA_ATTR_WEBSCROLL_SHOW);
|
|
176
|
+
const setup = parseProps(el.dataset[DATA_ATTR_SETUP]);
|
|
177
|
+
if (propsInitial && propsShow) {
|
|
178
|
+
const smsp = getScrollMagicSceneProps(el, setup);
|
|
179
|
+
const scene = new ScrollMagic.Scene(smsp);
|
|
180
|
+
scene.on("start", (e) => {
|
|
181
|
+
if (e.scrollDirection === "FORWARD") {
|
|
182
|
+
gsap.killTweensOf(el);
|
|
183
|
+
gsap.set(el, {...propsInitial.tween});
|
|
184
|
+
gsap.to(el, {duration: propsShow.time, ...propsShow.tween});
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
scene.addTo(scrollController.get());
|
|
188
|
+
this.scenes.push(scene);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* ############
|
|
193
|
+
* ### HIDE ###
|
|
194
|
+
* ############
|
|
195
|
+
*/
|
|
196
|
+
// ### ASwap Show / Hide ###
|
|
197
|
+
// hide webviews
|
|
198
|
+
webViewsHide() {
|
|
199
|
+
if (!this.container) {
|
|
200
|
+
console.warn("Unknown container", this);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const list = [...this.container.querySelectorAll('*[data-' + DATA_ATTR_WEBVIEW_HIDE + ']')];
|
|
204
|
+
list.forEach(this.webViewsElementHide.bind(this));
|
|
205
|
+
}
|
|
206
|
+
// showe webview element
|
|
207
|
+
webViewsElementHide(el, index) {
|
|
208
|
+
const propsHide = this.getTweenProps(el, DATA_ATTR_WEBVIEW_HIDE);
|
|
209
|
+
if (propsHide) {
|
|
210
|
+
gsap.killTweensOf(el);
|
|
211
|
+
gsap.to(el, {duration: propsHide.time, ...propsHide.tween});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
// ### Stagger ###
|
|
215
|
+
// Hide stagger
|
|
216
|
+
staggerHide() {
|
|
217
|
+
if (!this.container) {
|
|
218
|
+
console.warn("Unknown container", this);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
const list = [...this.container.querySelectorAll('*[data-' + DATA_ATTR_STAGGER_HIDE + ']')];
|
|
222
|
+
list.forEach(this.staggerListHide.bind(this));
|
|
223
|
+
}
|
|
224
|
+
// Hide stagger element
|
|
225
|
+
staggerListHide(el, index) {
|
|
226
|
+
const { selector } = parseProps(el.dataset[DATA_ATTR_SETUP]);
|
|
227
|
+
if (!selector) {
|
|
228
|
+
console.warn("Unknown selector for webflow stagger", el);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const items = [...el.querySelectorAll(selector)];
|
|
232
|
+
const propsHide = this.getTweenProps(el, DATA_ATTR_STAGGER_HIDE);
|
|
233
|
+
if (items.length && propsHide) {
|
|
234
|
+
gsap.killTweensOf(items);
|
|
235
|
+
gsap.to(items, {duration: propsHide.time, ...propsHide.tween});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
// ### ScrollMagic ###
|
|
239
|
+
/**
|
|
240
|
+
* hide scenes
|
|
241
|
+
*/
|
|
242
|
+
hideScrollmagicScenes() {
|
|
243
|
+
if (!this.container) {
|
|
244
|
+
console.warn("Unknown container", this);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const list = [...this.container.querySelectorAll('*[data-' + DATA_ATTR_WEBSCROLL_HIDE + ']')];
|
|
248
|
+
list.forEach(this.hideScrollmagicElement.bind(this));
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Hide element
|
|
252
|
+
* @param {DOM} el
|
|
253
|
+
* @param {Int} index
|
|
254
|
+
*/
|
|
255
|
+
hideScrollmagicElement(el, index) {
|
|
256
|
+
const propsHide = this.getTweenProps(el, DATA_ATTR_WEBSCROLL_HIDE);
|
|
257
|
+
if (propsHide) {
|
|
258
|
+
gsap.killTweensOf(el);
|
|
259
|
+
gsap.to(el, { duration: propsHide.time, ...propsHide.tween});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
// ## Destroy scrollmagic scenes
|
|
263
|
+
destroyScenes() {
|
|
264
|
+
this.scenes.forEach((scene) => {
|
|
265
|
+
scene.destroy();
|
|
266
|
+
scene = null;
|
|
267
|
+
})
|
|
268
|
+
this.scenes = [];
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* ###############
|
|
272
|
+
* ### HELPERS ###
|
|
273
|
+
* ###############
|
|
274
|
+
*/
|
|
275
|
+
// get animation props
|
|
276
|
+
getTweenProps(el, name) {
|
|
277
|
+
const dataAttrName = this.getDataAttributeName(name);
|
|
278
|
+
return getWebflowAnimationProps(el.dataset[dataAttrName]);
|
|
279
|
+
}
|
|
280
|
+
// replace data-x with dataX
|
|
281
|
+
getDataAttributeName(name) {
|
|
282
|
+
return name.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
}
|
|
286
|
+
export default WebflowView
|
package/scripts/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import aswapInstance from './aswap/ASwap'
|
|
|
2
2
|
import Controller from './aswap/Controller'
|
|
3
3
|
import ControllerImgLoad from './aswap/ControllerImgLoad'
|
|
4
4
|
import View from './aswap/View'
|
|
5
|
+
import WebflowView from './aswap/WebflowView'
|
|
5
6
|
// Bootstrap v5 helper
|
|
6
7
|
import bootsrap5 from './bootstrap/v5/Bootstrap5'
|
|
7
8
|
// showup
|
|
@@ -15,6 +16,7 @@ export default {
|
|
|
15
16
|
Controller,
|
|
16
17
|
ControllerImgLoad,
|
|
17
18
|
View,
|
|
19
|
+
WebflowView,
|
|
18
20
|
// boottstrap
|
|
19
21
|
bootsrap5,
|
|
20
22
|
// showup
|