Preview
Swipe the cards, or let them play. Tap one to open it, then tap back, press Escape, or drag it down.
Install
pnpx sothearo add card-carousel
It checks whether you use Vue, Nuxt or React, and adds only the files you need to your components folder, in card-carousel/. They're yours to change.
Usage
Give it items with an id and a color, then draw each card and its page. The page opens inside the carousel, so give the carousel the size you want the page to fill.
Projects.vue
<script setup lang="ts">
import CardCarousel from "@/components/card-carousel/CardCarousel.vue";
const projects = [
{ id: "aksar", color: "#ffd84d", name: "Aksar" },
{ id: "mitai", color: "#f07890", name: "Mitai" },
];
</script>
<template>
<CardCarousel :items="projects" :autoplay="4000" class="h-[560px]">
<template #card="{ item }">
<h3>{{ item.name }}</h3>
</template>
<template #detail="{ item, close }">
<button @click="close">
Back
</button>
<h2>{{ item.name }}</h2>
</template>
</CardCarousel>
</template>
How it moves
- Swiping uses the browser's own scrolling, so momentum, trackpads and touch feel native.
- Cards beside the centre shrink and fade a little, following your finger.
- The background blends from one card's colour to the next.
- Opening grows the card into the page, then the content fades in.
- Autoplay pauses while you hover, touch, focus or read a page, and stops for reduced motion.
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
items | Item[] | Cards to show. Each needs an id, and can have a color. | |
orientation | "horizontal" | "vertical" | "horizontal" | Swipe sideways, or up and down like stories. |
autoplay | number | Milliseconds per card. Leave it out to stay still. | |
label | string | "Cards" | Name for screen readers. |
v-model:open | string | The id of the open card. |
Drawing cards
| Slot | Gives you | What it draws |
|---|---|---|
#card | item, index, active | Each card. |
#detail | item, close | The page a card opens into. |
Customise
carousel.css
[data-card-carousel] {
--carousel-card-size: 70%;
--carousel-radius: 32px;
--carousel-gap: 12px;
}
Accessibility
- Cards are buttons, and the dots jump to a card.
- The open page is a dialog that closes with Escape.
- Motion and autoplay stop when the system asks for reduced motion.