Carousel
Usage
Drag with your mouse, scroll with your mouse wheel or use the navigation arrows to navigate.
Pass an array to the items
prop and use the default slot to display the content of each item.
{ "message": "You should use slots with <ContentRenderer>", "value": {}, "excerpt": false, "tag": "div" }
Snap
The carousel will snap the item to the center (snap-center
). You can use the snap
utility classes to change this behavior using the ui
prop:
Snap to start
<template>
<UCarousel v-slot="{ item }" :items="items" :ui="{ item: 'snap-start' }">
<img :src="item" width="200" height="300">
</UCarousel>
</template>
Snap to end
<template>
<UCarousel v-slot="{ item }" :items="items" :ui="{ item: 'snap-end' }">
<img :src="item" width="200" height="300">
</UCarousel>
</template>
Size
Each item will take its own size by default in the carousel. You can use the basis
/ width
utility classes to change this behavior using the ui
prop:
{ "message": "You should use slots with <ContentRenderer>", "value": {}, "excerpt": false, "tag": "div" }
In this example, we used basis-1/3
to display 3 items at a time but you can also use this to make the carousel full width using basis-full
and display only one item at a time:
{ "message": "You should use slots with <ContentRenderer>", "value": {}, "excerpt": false, "tag": "div" }
You can also set a width on the container to center the carousel:
{ "message": "You should use slots with <ContentRenderer>", "value": {}, "excerpt": false, "tag": "div" }
Navigation
Arrows
Use the arrows
prop to enable prev and next buttons, they will be automatically disabled when the carousel reaches the first or last item.
{ "message": "You should use slots with <ContentRenderer>", "value": {}, "excerpt": false, "tag": "div" }
You can also customize the prev and next buttons using the prev-button
and next-button
props:
{ "message": "You should use slots with <ContentRenderer>", "value": {}, "excerpt": false, "tag": "div" }
In this example, we move the buttons outside of the carousel container. You can also change this globally in ui.carousel.default.prevButton
and ui.carousel.default.nextButton
.
Indicators
Use the indicators
prop to display a list of buttons at the bottom of the carousel to navigate between items.
{ "message": "You should use slots with <ContentRenderer>", "value": {}, "excerpt": false, "tag": "div" }
The number of indicators will be automatically generated based on the number of items:
{ "message": "You should use slots with <ContentRenderer>", "value": {}, "excerpt": false, "tag": "div" }
Autoplay
You can easily implement an autoplay behavior using the exposed API through a template ref.
{ "message": "You should use slots with <ContentRenderer>", "value": {}, "excerpt": false, "tag": "div" }
Slots
default
You can put anything inside the default slot, not only images. You will have access to the item
and index
properties in the slot scope.
{ "message": "You should use slots with <ContentRenderer>", "value": {}, "excerpt": false, "tag": "div" }
prev
/ next
With the arrows
prop enabled, use the #prev
and #next
slots to set the content of the previous and next buttons. You will have access to the disabled
property and on-click
method in the slot scope.
{ "message": "You should use slots with <ContentRenderer>", "value": {}, "excerpt": false, "tag": "div" }
ui.arrows.wrapper
.indicator
With the indicators
prop enabled, use the #indicator
slot to set the content of the indicators. You will have access to the active
, page
properties and on-click
method in the slot scope.
{ "message": "You should use slots with <ContentRenderer>", "value": {}, "excerpt": false, "tag": "div" }
ui.indicators.wrapper
.Props
undefined
[]
"ltr"
config.default.prevButton as Button & {
class?: string;
}
config.default.nextButton as Button & {
class?: string;
}
false
false
API
When accessing the component via a template ref, you can use the following:
The current page.
The total number of pages.
Go to a specific page.
Go to the next page.
Go to the previous page.
Config
{ "message": "You should use slots with <ContentRenderer>", "value": {}, "excerpt": false, "tag": "div" }