Skip to content

Commit 0ab3d2e

Browse files
committed
Refactor Slider.svelte to use onDestroy for cleanup and improve slide transition handling
1 parent 59ad3dd commit 0ab3d2e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/routes/landing/Slider.svelte

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<script lang="ts">
2-
import { onMount } from 'svelte';
2+
import { onDestroy } from 'svelte';
33
44
let { images } = $props();
55
const sliderList = [images[images.length - 1], ...images, images[0]];
66
77
// Global variables
88
let changeDirection = $state(false);
9-
let timeout: ReturnType<typeof setTimeout> = undefined;
9+
let timeout: ReturnType<typeof setTimeout>;
1010
let currentSlideIndex = $state(1);
1111
let stopAnimation = $state(false);
1212
13-
function changeSlide(slideDirection) {
13+
function changeSlide(slideDirection: number) {
1414
if (changeDirection) return;
1515
changeDirection = true;
1616
slideDirection === 1 ? currentSlideIndex++ : currentSlideIndex--;
@@ -31,7 +31,7 @@
3131
});
3232
}
3333
34-
onMount(() => timeout && clearTimeout(timeout));
34+
onDestroy(() => timeout && clearTimeout(timeout));
3535
</script>
3636

3737
<div class="container px-0 relative flex overflow-clip aspect-video">
@@ -55,7 +55,7 @@
5555
alt={title}
5656
class={[
5757
'size-full object-cover translate-x-[calc(-1_*_var(--slide))] transform-gpu shrink-0 motion-safe:transition-transform motion-safe:duration-300',
58-
stopAnimation && 'motion-safe:transition-none'
58+
stopAnimation && 'motion-safe:transition-none motion-safe:duration-0'
5959
]}
6060
/>
6161
{/each}

0 commit comments

Comments
 (0)