Skip to content

Commit b168c37

Browse files
committed
fix: mobile workshop bounds
1 parent 22982f1 commit b168c37

File tree

1 file changed

+72
-16
lines changed

1 file changed

+72
-16
lines changed

src/components/FlowingWorkshops.astro

Lines changed: 72 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ const workshopData = workshops
2828
const mobileItemCount = Math.min(workshopData.length, Math.floor(workshopData.length * 0.6))
2929
const desktopItemCount = workshopData.length
3030
31-
// Omg math - different bounds for mobile and desktop
31+
// Omg math - different bounds for mobile portrait, mobile landscape, and desktop
3232
const duration = 25
3333
const topBound = 15
34-
const mobileBottomBound = 35
34+
const mobilePortraitBottomBound = 50
35+
const mobileLandscapeBottomBound = 35
3536
const desktopBottomBound = 55
36-
const mobileUsableRange = Math.max(0, mobileBottomBound - topBound)
37+
const mobilePortraitUsableRange = Math.max(0, mobilePortraitBottomBound - topBound)
38+
const mobileLandscapeUsableRange = Math.max(0, mobileLandscapeBottomBound - topBound)
3739
const desktopUsableRange = Math.max(0, desktopBottomBound - topBound)
3840
3941
// Helper: Fisher-Yates shuffle
@@ -47,10 +49,25 @@ function shuffle<T>(arr: T[]): T[] {
4749
return arr
4850
}
4951
50-
// Create positions for both mobile and desktop
51-
function createWorkshopItems(count: number, dataSet: typeof workshopData, isMobile: boolean) {
52-
const usableRange = isMobile ? mobileUsableRange : desktopUsableRange
53-
const bottomBound = isMobile ? mobileBottomBound : desktopBottomBound
52+
// Create positions for mobile portrait, mobile landscape, and desktop
53+
function createWorkshopItems(count: number, dataSet: typeof workshopData, mode: 'mobile-portrait' | 'mobile-landscape' | 'desktop') {
54+
let usableRange: number
55+
let bottomBound: number
56+
57+
switch (mode) {
58+
case 'mobile-portrait':
59+
usableRange = mobilePortraitUsableRange
60+
bottomBound = mobilePortraitBottomBound
61+
break
62+
case 'mobile-landscape':
63+
usableRange = mobileLandscapeUsableRange
64+
bottomBound = mobileLandscapeBottomBound
65+
break
66+
case 'desktop':
67+
usableRange = desktopUsableRange
68+
bottomBound = desktopBottomBound
69+
break
70+
}
5471
5572
const yPositions = Array.from({ length: count }, (_, k) => {
5673
const segment = usableRange / Math.max(1, count)
@@ -80,16 +97,38 @@ function createWorkshopItems(count: number, dataSet: typeof workshopData, isMobi
8097
})
8198
}
8299
83-
const mobileWorkshopItems = createWorkshopItems(mobileItemCount, workshopData, true)
84-
const desktopWorkshopItems = createWorkshopItems(desktopItemCount, workshopData, false)
100+
const mobilePortraitWorkshopItems = createWorkshopItems(mobileItemCount, workshopData, 'mobile-portrait')
101+
const mobileLandscapeWorkshopItems = createWorkshopItems(mobileItemCount, workshopData, 'mobile-landscape')
102+
const desktopWorkshopItems = createWorkshopItems(desktopItemCount, workshopData, 'desktop')
85103
86104
---
87105

88106
<div class="relative overflow-hidden flowing-workshop-container">
89-
<!-- Mobile workshops -->
90-
{mobileWorkshopItems.map((workshop, index) => (
107+
<!-- Mobile workshops - Portrait -->
108+
{mobilePortraitWorkshopItems.map((workshop, index) => (
109+
<div
110+
class={`absolute w-48 h-36 ${workshop.border} rounded-lg bg-white p-2 flowing-workshop xl:hidden mobile-portrait-only`}
111+
style={`
112+
top: ${workshop.y}%;
113+
--tilt: ${workshop.tilt}deg;
114+
transform: translateX(calc(100vw + 200px)) rotate(${workshop.tilt}deg);
115+
animation: flow-right-to-left-mobile 25s linear infinite;
116+
animation-delay: ${workshop.delay}s;
117+
`}
118+
>
119+
<img
120+
src={workshop.image}
121+
alt={workshop.title}
122+
class="w-full h-24 object-cover rounded"
123+
/>
124+
<p class="text-xs font-medium text-center text-gray-800 mt-1 px-1">{workshop.title}</p>
125+
</div>
126+
))}
127+
128+
<!-- Mobile workshops - Landscape -->
129+
{mobileLandscapeWorkshopItems.map((workshop, index) => (
91130
<div
92-
class={`absolute w-48 h-36 ${workshop.border} rounded-lg bg-white p-2 flowing-workshop xl:hidden`}
131+
class={`absolute w-48 h-36 ${workshop.border} rounded-lg bg-white p-2 flowing-workshop xl:hidden mobile-landscape-only`}
93132
style={`
94133
top: ${workshop.y}%;
95134
--tilt: ${workshop.tilt}deg;
@@ -162,26 +201,43 @@ const desktopWorkshopItems = createWorkshopItems(desktopItemCount, workshopData,
162201

163202
@media (max-width: 1279px) {
164203
.flowing-workshop-container {
165-
/* Default mobile height */
166204
height: 60vh;
167205
}
168206

169-
@media (max-aspect-ratio: 4/3) {
207+
@media (min-aspect-ratio: 4/3) {
170208
.flowing-workshop-container {
171209
height: 70vh;
172210
}
173211
}
174212

175-
@media (max-aspect-ratio: 3/2) {
213+
@media (min-aspect-ratio: 3/2) {
176214
.flowing-workshop-container {
177215
height: 80vh;
178216
}
179217
}
180218

181-
@media (max-aspect-ratio: 16/9) {
219+
@media (min-aspect-ratio: 16/9) {
182220
.flowing-workshop-container {
183221
height: 90vh;
184222
}
185223
}
224+
225+
.mobile-portrait-only {
226+
display: block;
227+
}
228+
229+
.mobile-landscape-only {
230+
display: none;
231+
}
232+
233+
@media (min-aspect-ratio: 4/3) {
234+
.mobile-portrait-only {
235+
display: none;
236+
}
237+
238+
.mobile-landscape-only {
239+
display: block;
240+
}
241+
}
186242
}
187243
</style>

0 commit comments

Comments
 (0)