diff --git a/src/lib/components/Carousel.svelte b/src/lib/components/Carousel.svelte index eba8cc707f..40510d5be1 100644 --- a/src/lib/components/Carousel.svelte +++ b/src/lib/components/Carousel.svelte @@ -11,31 +11,16 @@ } const { size = 'default', gap = 32, header, children }: Props = $props(); - let scroll = 0; - - function calculateScrollAmount(prev = false) { - const direction = prev ? -1 : 1; - const carouselSize = carousel?.clientWidth; - const childSize = (carousel.childNodes[0] as HTMLUListElement)?.clientWidth + gap; - - scroll = scroll || carouselSize; - - const numberOfItems = Math.floor(carouselSize / childSize); - const overflow = scroll % childSize; - const amount = numberOfItems * childSize - overflow * direction; - scroll += amount * direction; - return amount * direction; - } function next() { carousel.scrollBy({ - left: calculateScrollAmount(), + left: carousel.clientWidth, behavior: 'smooth' }); } function prev() { carousel.scrollBy({ - left: calculateScrollAmount(true), + left: -carousel.clientWidth, behavior: 'smooth' }); }