diff --git a/components/Carousel.tsx b/components/Carousel.tsx index 85c5935..bdd981d 100644 --- a/components/Carousel.tsx +++ b/components/Carousel.tsx @@ -22,11 +22,10 @@ const wrappedDistance = (a: number, b: number) => { const setOpacity = (emblaApi: EmblaCarouselType) => { const slideNodes = emblaApi.slideNodes(); - const slidesInView = slideNodes.map((_, index) => index); const currentPosition = emblaApi.scrollProgress(); - slidesInView.forEach((slideIndex) => { + slideNodes.forEach((_, slideIndex) => { const slidePosition = emblaApi.scrollSnapList()[slideIndex]; const opacity = clamp( 1 - wrappedDistance(slidePosition, currentPosition) * 8.4, @@ -47,10 +46,9 @@ const Carousel: React.FC = ({ slides, options }) => { useEffect(() => { if (!emblaApi) return; - + setOpacity(emblaApi); emblaApi.on("reInit", setOpacity).on("scroll", setOpacity); - }, [emblaApi]); return (