zz-shopify-components 0.34.1-beta.23 → 0.34.1-beta.24
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.
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
|
|
2
|
+
<style>
|
|
3
|
+
.zz-scrollTrigger-block-{{ block.id }} {
|
|
4
|
+
width: 100%;
|
|
5
|
+
height: 100vh;
|
|
6
|
+
background-color: {{ block.settings.background_color }};
|
|
7
|
+
padding: 0;
|
|
8
|
+
margin: 0;
|
|
9
|
+
position: relative;
|
|
10
|
+
{% if block.settings.scroll_direction == 'horizontal' %}
|
|
11
|
+
display: flex;
|
|
12
|
+
overflow-x: hidden;
|
|
13
|
+
{% else %}
|
|
14
|
+
overflow: hidden;
|
|
15
|
+
{% endif %}
|
|
16
|
+
}
|
|
17
|
+
.zz-scrollTrigger-block-{{ block.id }} .zz-scrollTrigger-item .responsive-width-image,
|
|
18
|
+
.zz-scrollTrigger-block-{{ block.id }} .zz-scrollTrigger-item .zz-video {
|
|
19
|
+
aspect-ratio: 16 / 9 !important;
|
|
20
|
+
max-width: 45vw !important;
|
|
21
|
+
{% comment %} border-radius: 12px; {% endcomment %}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.zz-scrollTrigger-block-{{ block.id }} .zz-scrollTrigger-item .content-video-container {
|
|
25
|
+
display: flex;
|
|
26
|
+
align-items: center;
|
|
27
|
+
justify-content: center;
|
|
28
|
+
{% comment %} border-radius: 12px; {% endcomment %}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
{% if block.settings.scroll_direction == 'horizontal' %}
|
|
33
|
+
.zz-scrollTrigger-block-{{ block.id }} .zz-scrollTrigger-item {
|
|
34
|
+
width: 100vw;
|
|
35
|
+
height: 100vh;
|
|
36
|
+
flex-shrink: 0;
|
|
37
|
+
display: flex;
|
|
38
|
+
align-items: center;
|
|
39
|
+
justify-content: center;
|
|
40
|
+
position: relative;
|
|
41
|
+
will-change: transform;
|
|
42
|
+
}
|
|
43
|
+
{% else %}
|
|
44
|
+
.zz-scrollTrigger-block-{{ block.id }} .zz-scrollTrigger-item {
|
|
45
|
+
width: 100%;
|
|
46
|
+
height: 100vh;
|
|
47
|
+
position: absolute;
|
|
48
|
+
top: 0;
|
|
49
|
+
left: 0;
|
|
50
|
+
display: flex;
|
|
51
|
+
align-items: center;
|
|
52
|
+
justify-content: center;
|
|
53
|
+
will-change: transform, opacity;
|
|
54
|
+
}
|
|
55
|
+
{% endif %}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@media (max-width: 768px) {
|
|
59
|
+
.zz-scrollTrigger-block-{{ block.id }} .zz-scrollTrigger-item {
|
|
60
|
+
height: 100vh;
|
|
61
|
+
width: 100%;
|
|
62
|
+
{% if block.settings.scroll_direction == 'horizontal' %}
|
|
63
|
+
width: 100vw;
|
|
64
|
+
padding: 0 10px;
|
|
65
|
+
{% else %}
|
|
66
|
+
padding: 0 10px;
|
|
67
|
+
{% endif %}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
</style>
|
|
71
|
+
|
|
72
|
+
<div class="zz-scrollTrigger-block zz-scrollTrigger-block-{{ block.id }}" id="zz-scrollTrigger-block-{{ block.id }}">
|
|
73
|
+
{% for item in block.blocks %}
|
|
74
|
+
<div class="zz-scrollTrigger-item">
|
|
75
|
+
{% render item %}
|
|
76
|
+
</div>
|
|
77
|
+
{% endfor %}
|
|
78
|
+
</div>
|
|
79
|
+
|
|
80
|
+
<script>
|
|
81
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
82
|
+
if (typeof gsap === 'undefined' || typeof ScrollTrigger === 'undefined') {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
gsap.registerPlugin(ScrollTrigger);
|
|
87
|
+
ScrollTrigger.config({
|
|
88
|
+
ignoreMobileResize: true,
|
|
89
|
+
autoRefreshEvents: "visibilitychange,DOMContentLoaded,load"
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
if (window.innerWidth < 1024) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let items = gsap.utils.toArray('#zz-scrollTrigger-block-{{ block.id }} .zz-scrollTrigger-item');
|
|
97
|
+
let scrollTriggerInstances = [];
|
|
98
|
+
|
|
99
|
+
if (items.length > 1) {
|
|
100
|
+
{% if block.settings.scroll_direction == 'horizontal' %}
|
|
101
|
+
const endValue = window.innerHeight * 1.3 * (items.length - 1);
|
|
102
|
+
|
|
103
|
+
const horizontalST = gsap.to(items, {
|
|
104
|
+
xPercent: -100 * (items.length - 1),
|
|
105
|
+
ease: 'none',
|
|
106
|
+
scrollTrigger: {
|
|
107
|
+
trigger: '#zz-scrollTrigger-block-{{ block.id }}',
|
|
108
|
+
start: 'top top',
|
|
109
|
+
end: `+=${endValue}`,
|
|
110
|
+
pin: true,
|
|
111
|
+
scrub: 1,
|
|
112
|
+
markers: false,
|
|
113
|
+
{% if block.settings.enable_snap %}
|
|
114
|
+
snap: {
|
|
115
|
+
snapTo: 1 / (items.length - 1),
|
|
116
|
+
duration: 0.5,
|
|
117
|
+
delay: 0.1,
|
|
118
|
+
directional: false,
|
|
119
|
+
ease: "power2.inOut"
|
|
120
|
+
},
|
|
121
|
+
{% endif %}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
scrollTriggerInstances.push(horizontalST.scrollTrigger);
|
|
125
|
+
{% else %}
|
|
126
|
+
gsap.set(items[0], { y: 0, opacity: 1 });
|
|
127
|
+
gsap.set(items.slice(1), { y: '10vh', opacity: 0 });
|
|
128
|
+
|
|
129
|
+
const endValue = window.innerHeight * 1 * (items.length - 1); // 增加滚动距离让动画更平滑
|
|
130
|
+
|
|
131
|
+
let tl = gsap.timeline({
|
|
132
|
+
scrollTrigger: {
|
|
133
|
+
trigger: '#zz-scrollTrigger-block-{{ block.id }}',
|
|
134
|
+
start: 'top top',
|
|
135
|
+
end: `+=${endValue}`,
|
|
136
|
+
pin: true,
|
|
137
|
+
scrub: 1,
|
|
138
|
+
markers: false,
|
|
139
|
+
{% if block.settings.enable_snap %}
|
|
140
|
+
snap: {
|
|
141
|
+
snapTo: 1 / (items.length - 1),
|
|
142
|
+
duration: 0.2,
|
|
143
|
+
delay: 0.05,
|
|
144
|
+
directional: true,
|
|
145
|
+
ease: "power2.out"
|
|
146
|
+
},
|
|
147
|
+
{% endif %}
|
|
148
|
+
refreshPriority: -1,
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
scrollTriggerInstances.push(tl.scrollTrigger);
|
|
152
|
+
|
|
153
|
+
items.forEach((item, index) => {
|
|
154
|
+
if (index < items.length - 1) {
|
|
155
|
+
let currentItem = items[index];
|
|
156
|
+
let nextItem = items[index + 1];
|
|
157
|
+
|
|
158
|
+
tl.to(currentItem, {
|
|
159
|
+
y: '-10vh',
|
|
160
|
+
opacity: 0,
|
|
161
|
+
duration: 0.1,
|
|
162
|
+
ease: "power2.inOut"
|
|
163
|
+
})
|
|
164
|
+
.fromTo(nextItem, {
|
|
165
|
+
y: '10vh',
|
|
166
|
+
opacity: 0
|
|
167
|
+
}, {
|
|
168
|
+
y: 0,
|
|
169
|
+
opacity: 1,
|
|
170
|
+
duration: 0.1,
|
|
171
|
+
ease: "power2.inOut"
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
{% endif %}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
window.addEventListener('beforeunload', () => {
|
|
179
|
+
scrollTriggerInstances.forEach(st => {
|
|
180
|
+
if (st) st.kill();
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
let resizeTimeout;
|
|
185
|
+
{% comment %} window.addEventListener('resize', () => {
|
|
186
|
+
clearTimeout(resizeTimeout);
|
|
187
|
+
resizeTimeout = setTimeout(() => {
|
|
188
|
+
ScrollTrigger.refresh();
|
|
189
|
+
}, 250);
|
|
190
|
+
}); {% endcomment %}
|
|
191
|
+
});
|
|
192
|
+
</script>
|
|
193
|
+
|
|
194
|
+
{% schema %}
|
|
195
|
+
{
|
|
196
|
+
"name": "ZZ ScrollTrigger Block",
|
|
197
|
+
"settings": [
|
|
198
|
+
{
|
|
199
|
+
"type": "select",
|
|
200
|
+
"id": "scroll_direction",
|
|
201
|
+
"label": "滚动方向",
|
|
202
|
+
"options": [
|
|
203
|
+
{
|
|
204
|
+
"value": "vertical",
|
|
205
|
+
"label": "上下切换"
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
"value": "horizontal",
|
|
209
|
+
"label": "左右切换"
|
|
210
|
+
}
|
|
211
|
+
],
|
|
212
|
+
"default": "vertical",
|
|
213
|
+
"info": "选择滚动的方向模式"
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
"type": "checkbox",
|
|
217
|
+
"id": "enable_snap",
|
|
218
|
+
"label": "启用吸附",
|
|
219
|
+
"default": false
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"type": "color_background",
|
|
223
|
+
"id": "background_color",
|
|
224
|
+
"label": "背景颜色",
|
|
225
|
+
"default": "transparent"
|
|
226
|
+
}
|
|
227
|
+
],
|
|
228
|
+
"blocks": [
|
|
229
|
+
{
|
|
230
|
+
"type": "@theme"
|
|
231
|
+
}
|
|
232
|
+
],
|
|
233
|
+
"presets": [
|
|
234
|
+
{
|
|
235
|
+
"name": "ScrollTrigger滚动容器Block",
|
|
236
|
+
"blocks": [
|
|
237
|
+
{
|
|
238
|
+
"type": "zz-title",
|
|
239
|
+
"settings": {
|
|
240
|
+
"pc_title": "<p>滚动容器Block</p>"
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
]
|
|
244
|
+
}
|
|
245
|
+
]
|
|
246
|
+
}
|
|
247
|
+
{% endschema %}
|
package/package.json
CHANGED
|
@@ -46,6 +46,8 @@
|
|
|
46
46
|
findTargetIframe();
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
|
+
|
|
50
|
+
let isLogin = false;
|
|
49
51
|
|
|
50
52
|
// 监听滚动事件
|
|
51
53
|
window.addEventListener('scroll', function() {
|
|
@@ -119,6 +121,77 @@
|
|
|
119
121
|
setTimeout(findTargetIframe, 1000);
|
|
120
122
|
return null;
|
|
121
123
|
}
|
|
124
|
+
|
|
125
|
+
function checkLogin() {
|
|
126
|
+
console.log("jwt checkLogin")
|
|
127
|
+
if(isLogin) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if(window.__ZZ_ANALYTICS_CONTEXT__ && window.__ZZ_ANALYTICS_CONTEXT__.huid) {
|
|
131
|
+
const params = {
|
|
132
|
+
email_verified: true,
|
|
133
|
+
external_id: window.__ZZ_ANALYTICS_CONTEXT__.huid
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
if(window.__ZZ_ANALYTICS_CONTEXT__.email) {
|
|
137
|
+
params.email = window.__ZZ_ANALYTICS_CONTEXT__.email;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if(window.__ZZ_ANALYTICS_CONTEXT__.firstName || window.__ZZ_ANALYTICS_CONTEXT__.lastName) {
|
|
141
|
+
const nameParts = [];
|
|
142
|
+
if(window.__ZZ_ANALYTICS_CONTEXT__.firstName) nameParts.push(window.__ZZ_ANALYTICS_CONTEXT__.firstName);
|
|
143
|
+
if(window.__ZZ_ANALYTICS_CONTEXT__.lastName) nameParts.push(window.__ZZ_ANALYTICS_CONTEXT__.lastName);
|
|
144
|
+
params.name = nameParts.join(' ');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
handleLogin(params);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function handleLogin(params) {
|
|
152
|
+
const { email_verified } = params;
|
|
153
|
+
isLogin = true;
|
|
154
|
+
zE("messenger", "loginUser", function (callback) {
|
|
155
|
+
try {
|
|
156
|
+
const jwt = requestMessagingJwt(params);
|
|
157
|
+
callback(jwt)
|
|
158
|
+
} catch (error) {
|
|
159
|
+
console.log('request-jwt', error);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
}, function (error) {
|
|
163
|
+
if(error && email_verified) {
|
|
164
|
+
handleLogin({...params, email_verified: false})
|
|
165
|
+
}
|
|
166
|
+
console.log('jwt login-error', error);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async function requestMessagingJwt(params) {
|
|
171
|
+
const response = await fetch('https://static.zerozeroplatform.com/zendesk-jwt', {
|
|
172
|
+
method: 'POST',
|
|
173
|
+
headers: {
|
|
174
|
+
'Content-Type': 'application/json'
|
|
175
|
+
},
|
|
176
|
+
body: JSON.stringify(params || {})
|
|
177
|
+
});
|
|
178
|
+
if (!response.ok) {
|
|
179
|
+
throw new Error('Failed to fetch messaging jwt');
|
|
180
|
+
}
|
|
181
|
+
const data = await response.json();
|
|
182
|
+
if (!data || !data.jwt) {
|
|
183
|
+
throw new Error('Messaging jwt request failed');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return data.jwt;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (typeof subscribe === 'function') {
|
|
190
|
+
subscribe('zz:user-session-updated', checkLogin);
|
|
191
|
+
}
|
|
192
|
+
// 初始化检查登录状态
|
|
193
|
+
checkLogin();
|
|
194
|
+
|
|
122
195
|
});
|
|
123
196
|
</script>
|
|
124
197
|
|