Skip to content

Commit

Permalink
fix(carousel-image): preload images
Browse files Browse the repository at this point in the history
  • Loading branch information
jsun969 committed Feb 18, 2024
1 parent 4f91732 commit da9e958
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/components/ImageCarousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,31 @@ export default function ImageCarousel({ images, width, height }: ImageCarouselPr
});

return (
<div
className={`transition-opacity duration-500 ease-in-out ${
isTransitioning ? 'opacity-0' : 'opacity-100'
}`}
>
<Image
src={images[currentImageIndex].src}
alt={images[currentImageIndex].alt}
width={width}
height={height}
className="h-full w-full object-cover"
/>
</div>
<>
{images.map((image, i) => (
<Image
key={i}
src={image.src}
alt={image.alt}
width={width}
height={height}
className="hidden"
priority
/>
))}
<div
className={`transition-opacity duration-500 ease-in-out ${
isTransitioning ? 'opacity-0' : 'opacity-100'
}`}
>
<Image
src={images[currentImageIndex].src}
alt={images[currentImageIndex].alt}
width={width}
height={height}
className="h-full w-full object-cover"
/>
</div>
</>
);
}

0 comments on commit da9e958

Please sign in to comment.