Carousel
画像やテキストなどの要素をカルーセルのように循環表示するためのスライドショーコンポーネントです。
いつ使用するか
同じレベルのコンテンツのグループがある場合。コンテンツスペースが不十分な場合、回転ドアの形でスペースを節約するために使用できます。写真やカードのグループによく使用されます。
使用例
astro
---
import Carousel from '@/components/data-display/Carousel.astro';
import CarouselItem from '@/components/data-display/CarouselItem.astro';
---
<Carousel class="rounded-lg h-48">
<CarouselItem>
<div class="bg-blue-500 h-full">Slide 1</div>
</CarouselItem>
<CarouselItem>
<div class="bg-green-500 h-full">Slide 2</div>
</CarouselItem>
</Carousel> 自動再生
`autoplay`プロパティを追加することで、自動循環を有効にできます。`autoplayInterval`を使用して速度を制御できます(ミリ秒単位、デフォルトは3000)。カルーセルにカーソルを合わせると自動的に一時停止します。
astro
<Carousel autoplay autoplayInterval={2000}>
<!-- items -->
</Carousel> コントロールとアスペクト比
ナビゲーション矢印を表示するには`showControls`プロパティを使用します。`aspectRatio`プロパティは一貫した寸法を強制するのに役立ちます(`video`、`square`、または`auto`)。
astro
<Carousel showControls aspectRatio="video" class="rounded-lg">
<CarouselItem>
<div class="bg-blue-500 h-full flex items-center justify-center">1</div>
</CarouselItem>
<CarouselItem>
<div class="bg-green-500 h-full flex items-center justify-center">2</div>
</CarouselItem>
</Carousel> API リファレンス
| プロパティ | 説明 | タイプ | デフォルト |
|---|---|---|---|
| autoplay | Whether to automatically cycle through the items. | boolean | false |
| autoplayInterval | The interval in milliseconds for autoplay. | number | 3000 |
| showDots | Whether to show the pagination dots. | boolean | true |
| showControls | Whether to show the next/previous navigation arrows. | boolean | false |
| aspectRatio | Enforces a specific aspect ratio for the carousel. | 'video' | 'square' | 'auto' | 'auto' |
| class | Additional CSS classes to apply to the carousel container. | string | - |