|
26 | 26 | let animationFrame = 0;
|
27 | 27 | let lastFrameTime = Date.now();
|
28 | 28 | let translateSpeed = 0.9; // Adjust for slower or faster animation
|
| 29 | +
|
29 | 30 | let imageContainer: HTMLElement;
|
30 |
| - $: imageContainerWidth = imageContainer?.clientWidth ?? imageModules.length * 2 * 500; |
31 |
| - $: maxScroll = -imageContainerWidth + (imageContainer?.parentElement?.clientWidth ?? 1000); |
| 31 | + let imageContainerWidth: number; |
| 32 | + let maxScroll: number; |
| 33 | + $: { |
| 34 | + recalculateSizes(imageContainer); |
| 35 | + } |
| 36 | +
|
| 37 | + function recalculateSizes(imageContainer: HTMLElement) { |
| 38 | + imageContainerWidth = imageContainer?.clientWidth ?? imageModules.length * 2 * 500; |
| 39 | + maxScroll = -imageContainerWidth + (imageContainer?.parentElement?.clientWidth ?? 1000); |
| 40 | + boundsCheck(); |
| 41 | + } |
32 | 42 |
|
33 | 43 | function animate() {
|
34 | 44 | const now = Date.now();
|
|
64 | 74 |
|
65 | 75 | const scrollWidth = imageContainer.children[0].clientWidth;
|
66 | 76 | translateX = direction === 'left' ? translateX + scrollWidth : translateX - scrollWidth;
|
| 77 | + boundsCheck(); |
| 78 | + } |
| 79 | +
|
| 80 | + function boundsCheck() { |
67 | 81 | if (translateX > 0) {
|
68 | 82 | translateX = 0;
|
69 | 83 | } else if (translateX < maxScroll) {
|
|
82 | 96 | });
|
83 | 97 | </script>
|
84 | 98 |
|
| 99 | +<svelte:window on:resize={() => recalculateSizes(imageContainer)} /> |
85 | 100 | <div
|
86 |
| - class="flex-center relative w-full flex-col bg-fountain px-5 py-32 text-black" |
| 101 | + class="flex-center relative w-full flex-col bg-fountain px-5 py-16 text-black" |
87 | 102 | id="past-events"
|
88 | 103 | >
|
89 | 104 | <div class="text-4xl">Past Events</div>
|
90 | 105 | <div class="m-auto flex w-full overflow-hidden text-xl">
|
91 | 106 | <div class="flex min-w-[min-content] gap-2" bind:this={imageContainer}>
|
92 | 107 | {#each [...imageModules, ...imageModules] as module}
|
93 | 108 | <div
|
94 |
| - class="picture-container flex aspect-[4/3] w-full items-center justify-center object-cover md:w-96" |
| 109 | + class="picture-container flex aspect-[4/3] w-[80vw] items-center justify-center object-cover md:w-96" |
95 | 110 | class:pause={!isPlaying}
|
96 | 111 | style={`transform: translateX(${translateX}px);`}
|
97 | 112 | >
|
98 | 113 | <enhanced:img
|
99 | 114 | class="h-full w-full object-cover"
|
100 | 115 | src={module.default}
|
101 | 116 | alt="A past event"
|
| 117 | + sizes="(min-width:1920px) 1280px, (min-width:1080px) 640px, (min-width:768px) 400px" |
102 | 118 | />
|
103 | 119 | </div>
|
104 | 120 | {/each}
|
|
0 commit comments