Carousel
Eine Diashow-Komponente zum Durchlaufen von Elementen – Bildern oder Texten – wie in einem Karussell.
Wann zu verwenden
Wenn eine Gruppe von Inhalten auf derselben Ebene vorhanden ist. Bei unzureichendem Inhaltsraum kann es verwendet werden, um Platz in Form einer Drehtür zu sparen. Häufig für eine Gruppe von Bildern/Karten verwendet.
Beispielverwendung
---
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> Automatische Wiedergabe
Sie können das automatische Durchlaufen aktivieren, indem Sie die Eigenschaft `autoplay` hinzufügen. Sie können die Geschwindigkeit mit `autoplayInterval` (in ms, Standard 3000) steuern. Wenn Sie mit der Maus über das Karussell fahren, wird es automatisch angehalten.
<Carousel autoplay autoplayInterval={2000}>
<!-- items -->
</Carousel> Steuerelemente & Seitenverhältnis
Verwenden Sie die Eigenschaft `showControls`, um Navigationspfeile anzuzeigen. Die Eigenschaft `aspectRatio` hilft dabei, konsistente Abmessungen zu erzwingen (`video`, `square` oder `auto`).
<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-Referenz
| Eigenschaft | Beschreibung | Typ | Standard |
|---|---|---|---|
| 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 | - |