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 | - |