-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardSpread.html
More file actions
391 lines (363 loc) · 17.8 KB
/
Copy pathCardSpread.html
File metadata and controls
391 lines (363 loc) · 17.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Card Spread Animation</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-color: #f0f0f0;
--text-color: #111;
--card-title-color: #ffffff;
}
body, html {
margin: 0;
padding: 0;
font-family: 'Inter', sans-serif;
background-color: var(--bg-color);
color: var(--text-color);
}
/* --- Default Styles (Assume Desktop) --- */
.scroll-section {
height: 400vh; /* Desktop scroll height */
}
.cards-container-wrapper {
position: sticky;
top: 0;
height: 100vh;
overflow: hidden;
}
#cards-collection {
position: relative;
width: 20vw;
height: 100vh;
margin: 0 auto;
}
.card {
position: absolute;
width: 20vw;
height: 100vh;
border-radius: 16px;
display: flex;
justify-content: center;
align-items: center;
font-size: 5rem;
font-weight: bold;
overflow: hidden;
color: rgba(255, 255, 255, 0.8);
will-change: transform, height, opacity; /* Performance hint */
transform: translateX(0); /* Default desktop state */
}
.card img {
width: 100%;
height: 100%;
object-fit: cover;
position: absolute;
top: 0;
left: 0;
z-index: 1;
}
.card-content {
position: absolute;
bottom: 0;
left: 0;
right: 0;
padding: 2rem;
z-index: 2;
text-align: center;
color: var(--card-title-color);
background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
}
.card-content h2 {
font-size: 2rem;
font-weight: 700;
margin: 0 0 0.5rem 0;
}
.card-content p {
font-size: 1rem;
font-weight: 400;
margin: 0;
}
/* Z-index for desktop stacking */
#card-1 { z-index: 3; }
#card-2 { z-index: 4; }
#card-3 { z-index: 5; }
#card-4 { z-index: 2; }
#card-5 { z-index: 1; }
/* --- Mobile Styles --- */
@media (max-width: 768px) {
.scroll-section {
/*
FIX: Changed height to 500vh.
This provides 400vh of total scroll distance (500vh - 100vh viewport).
This 400vh maps to the 0-100% 'cover' range,
allowing each of the 4 card transitions (25% each)
to map perfectly to 100vh of scrolling.
*/
height: 500vh;
}
#cards-collection {
width: 90vw;
}
.card {
width: 100%; /* Full width of the collection */
height: 75vh;
left: 0;
top: 12.5vh; /* Center vertically with margin */
/* Card 1 starts in view */
transform: translateY(0);
will-change: transform; /* Add will-change for mobile */
}
/* Initially hide cards 2-5 below the viewport via CSS */
/* This MUST be set correctly for fill: 'both' to work */
#card-2, #card-3, #card-4, #card-5 {
transform: translateY(100vh);
}
.card-content {
text-align: left;
padding: 1.5rem;
}
.card-content h2 {
font-size: 1.5rem;
}
.card-content p {
font-size: 0.9rem;
}
/* Z-index for mobile stacking order: Card 1 is at the bottom, Card 5 is at the top. */
#card-1 { z-index: 1; }
#card-2 { z-index: 2; }
#card-3 { z-index: 3; }
#card-4 { z-index: 4; }
#card-5 { z-index: 5; }
}
@media (prefers-reduced-motion: reduce) {
.card {
transform: none !important;
height: 100vh !important;
opacity: 1 !important;
}
/* Make sure desktop cards are visible */
@media (min-width: 769px) {
.card { height: 85vh !important; } /* Match end state height */
#card-1 { transform: translateX(-40vw) !important; }
#card-2 { transform: translateX(-20vw) !important; }
#card-3 { transform: translateX(0) !important; }
#card-4 { transform: translateX(20vw) !important; }
#card-5 { transform: translateX(40vw) !important; }
}
/* Ensure all mobile cards are visible */
@media (max-width: 768px) {
#card-1, #card-2, #card-3, #card-4, #card-5 {
transform: translateY(0) !important;
}
}
}
</style>
</head>
<body>
<wix-interact-element data-wix-path=".scroll-section">
<section class="scroll-section">
<div class="cards-container-wrapper">
<wix-interact-element data-wix-path="#cards-collection">
<div id="cards-collection">
<wix-interact-element data-wix-path="#card-1">
<div id="card-1" class="card">
<img src="https://images.unsplash.com/photo-1506744038136-46273834b3fb?q=80&w=2070&auto=format&fit=crop" alt="Misty mountains" onerror="this.style.display='none'">
<div class="card-content">
<h2>Serene Peaks</h2>
<p>Find your calm</p>
</div>
</div>
</wix-interact-element>
<wix-interact-element data-wix-path="#card-2">
<div id="card-2" class="card">
<img src="https://images.unsplash.com/photo-1501854140801-50d01698950b?q=80&w=2475&auto=format&fit=crop" alt="Green hills" onerror="this.style.display='none'">
<div class="card-content">
<h2>Rolling Hills</h2>
<p>Explore the landscape</p>
</div>
</div>
</wix-interact-element>
<wix-interact-element data-wix-path="#card-3">
<div id="card-3" class="card">
<img src="https://images.unsplash.com/photo-1470770841072-f978cf4d019e?q=80&w=2070&auto=format&fit=crop" alt="Mountain lake" onerror="this.style.display='none'">
<div class="card-content">
<h2>Alpine Lake</h2>
<p>Reflect and relax</p>
</div>
</div>
</wix-interact-element>
<wix-interact-element data-wix-path="#card-4">
<div id="card-4" class="card">
<img src="https://images.unsplash.com/photo-1433086966358-54859d0ed716?q=80&w=1974&auto=format&fit=crop" alt="Waterfall" onerror="this.style.display='none'">
<div class="card-content">
<h2>Hidden Falls</h2>
<p>Discover nature's power</p>
</div>
</div>
</wix-interact-element>
<wix-interact-element data-wix-path="#card-5">
<div id="card-5" class="card">
<img src="https://images.unsplash.com/photo-1511884642898-4c92249e20b6?q=80&w=2070&auto=format&fit=crop" alt="Forest from above" onerror="this.style.display='none'">
<div class="card-content">
<h2>Forest Canopy</h2>
<p>Breathe the fresh air</p>
</div>
</div>
</wix-interact-element>
</div>
</wix-interact-element>
</div>
</section>
</wix-interact-element>
<script type="module">
import { Interact } from 'https://esm.sh/@wix/interact@1.78.0';
// Keep track of initialized instances
window.InteractInstances = window.InteractInstances || [];
function destroyInstances() {
if (window.InteractInstances) {
// Assuming Interact.destroy() or similar exists.
// If not, this part needs adjustment based on library API.
window.InteractInstances.forEach(instance => instance.destroy ? instance.destroy() : null);
window.InteractInstances = [];
}
}
function setupAnimations() {
// Destroy any previous instances before creating new ones
destroyInstances();
// Desktop Configuration
const desktopConfig = {
interactions: [
{
key: '.scroll-section',
trigger: 'viewProgress',
effects: [
{
key: '.card',
keyframeEffect: { name: 'card-shrink', keyframes: [{ height: '100vh' }, { height: '85vh' }] },
rangeStart: { name: 'cover', offset: { type: 'percentage', value: 20 } },
rangeEnd: { name: 'cover', offset: { type: 'percentage', value: 80 } },
easing: 'cubic-bezier(0.42, 0, 0.58, 1)', fill: 'both'
},
{
key: '#card-1',
keyframeEffect: { name: 'card-1-move', keyframes: [{ transform: 'translateX(0)' }, { transform: 'translateX(-40vw)' }] },
rangeStart: { name: 'cover', offset: { type: 'percentage', value: 20 } },
rangeEnd: { name: 'cover', offset: { type: 'percentage', value: 80 } },
easing: 'cubic-bezier(0.42, 0, 0.58, 1)', fill: 'both'
},
{
key: '#card-2',
keyframeEffect: { name: 'card-2-move', keyframes: [{ transform: 'translateX(0)' }, { transform: 'translateX(-20vw)' }] },
rangeStart: { name: 'cover', offset: { type: 'percentage', value: 20 } },
rangeEnd: { name: 'cover', offset: { type: 'percentage', value: 80 } },
easing: 'cubic-bezier(0.42, 0, 0.58, 1)', fill: 'both'
},
{ // Keep card 3 centered
key: '#card-3',
keyframeEffect: { name: 'card-3-move', keyframes: [{ transform: 'translateX(0)' }, { transform: 'translateX(0)' }] },
rangeStart: { name: 'cover', offset: { type: 'percentage', value: 20 } },
rangeEnd: { name: 'cover', offset: { type: 'percentage', value: 80 } },
easing: 'cubic-bezier(0.42, 0, 0.58, 1)', fill: 'both'
},
{
key: '#card-4',
keyframeEffect: { name: 'card-4-move', keyframes: [{ transform: 'translateX(0)' }, { transform: 'translateX(20vw)' }] },
rangeStart: { name: 'cover', offset: { type: 'percentage', value: 20 } },
rangeEnd: { name: 'cover', offset: { type: 'percentage', value: 80 } },
easing: 'cubic-bezier(0.42, 0, 0.58, 1)', fill: 'both'
},
{
key: '#card-5',
keyframeEffect: { name: 'card-5-move', keyframes: [{ transform: 'translateX(0)' }, { transform: 'translateX(40vw)' }] },
rangeStart: { name: 'cover', offset: { type: 'percentage', value: 20 } },
rangeEnd: { name: 'cover', offset: { type: 'percentage', value: 80 } },
easing: 'cubic-bezier(0.42, 0, 0.58, 1)', fill: 'both'
}
]
}
]
};
// Mobile "Deck of Cards" Configuration using percentage-based cover ranges
const mobileConfig = {
interactions: [
{
key: '.scroll-section',
trigger: 'viewProgress',
effects: [
// Card 1 stays in place (starts at translateY(0) via CSS)
// Card 2 scrolls IN over Card 1 (0% -> 25%)
{
key: '#card-2',
keyframeEffect: { name: 'card-2-in', keyframes: [{ transform: 'translateY(100vh)' }, { transform: 'translateY(0)' }] },
rangeStart: { name: 'contain', offset: { type: 'percentage', value: 0 } },
rangeEnd: { name: 'contain', offset: { type: 'percentage', value: 25 } },
easing: 'linear', fill: 'both'
},
{ // Card 3 scrolls IN over Card 2 (25% -> 50%)
key: '#card-3',
keyframeEffect: { name: 'card-3-in', keyframes: [{ transform: 'translateY(100vh)' }, { transform: 'translateY(0)' }] },
rangeStart: { name: 'contain', offset: { type: 'percentage', value: 25 } },
rangeEnd: { name: 'contain', offset: { type: 'percentage', value: 50 } },
easing: 'linear', fill: 'both'
},
{ // Card 4 scrolls IN over Card 3 (50% -> 75%)
key: '#card-4',
keyframeEffect: { name: 'card-4-in', keyframes: [{ transform: 'translateY(100vh)' }, { transform: 'translateY(0)' }] },
rangeStart: { name: 'contain', offset: { type: 'percentage', value: 50 } },
rangeEnd: { name: 'contain', offset: { type: 'percentage', value: 75 } },
easing: 'linear', fill: 'both'
},
{ // Card 5 scrolls IN over Card 4 (75% -> 100%)
key: '#card-5',
keyframeEffect: { name: 'card-5-in', keyframes: [{ transform: 'translateY(100vh)' }, { transform: 'translateY(0)' }] },
rangeStart: { name: 'contain', offset: { type: 'percentage', value: 75 } },
rangeEnd: { name: 'contain', offset: { type: 'percentage', value: 100 } },
easing: 'linear', fill: 'both'
}
]
}
]
};
// Check window width and apply the correct configuration
if (window.innerWidth < 768) {
// Reset styles potentially set by desktop config
document.querySelectorAll('.card').forEach(card => {
card.style.height = ''; // Reset height
// Ensure correct starting transform based on ID
const cardId = card.id;
if (cardId === 'card-1') {
card.style.transform = 'translateY(0)';
} else if (cardId && cardId !== 'card-1') {
card.style.transform = 'translateY(100vh)';
} else {
card.style.transform = ''; // Clear for desktop cards if needed
}
});
const mobileInstance = Interact.create(mobileConfig);
window.InteractInstances.push(mobileInstance);
} else {
// Reset styles potentially set by mobile config
document.querySelectorAll('.card').forEach(card => {
card.style.height = ''; // Reset height
card.style.transform = ''; // Clear inline transform
});
const desktopInstance = Interact.create(desktopConfig);
window.InteractInstances.push(desktopInstance);
}
}
// Initial setup on load
window.addEventListener('load', setupAnimations);
// Debounced resize handler
let resizeTimeout;
window.addEventListener('resize', () => {
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(() => {
// Rerun setup without reloading the page
setupAnimations();
}, 250);
});
</script>
</body>
</html>