- Plugins
- Carousel
Plugins
Tailwind CSS Carousel
A slideshow component for cycling through elements-images or slides of text-like a carousel.
Installation
To get started, install Carousel plugin via npm, else you can skip this step if you are already using Preline UI as a package.
npm i @preline/carousel
Basic usage
Prefer to create your own style? Here is a completely unstylized example.
<div data-hs-carousel='{
"loadingClasses": "opacity-0"
}' class="relative">
<div class="hs-carousel relative overflow-hidden w-full min-h-64">
<div class="hs-carousel-body absolute top-0 bottom-0 start-0 flex flex-nowrap transition-transform duration-700 opacity-0">
<div class="hs-carousel-slide">
1
</div>
<div class="hs-carousel-slide">
2
</div>
<div class="hs-carousel-slide">
3
</div>
</div>
</div>
<button type="button" class="hs-carousel-prev">
<span aria-hidden="true">«</span>
<span class="sr-only">Previous</span>
</button>
<button type="button" class="hs-carousel-next">
<span class="sr-only">Next</span>
<span aria-hidden="true">»</span>
</button>
</div>
Methods
The HSCarousel
object is contained within the global window
object
Go to some slide by button click example (public method).
const carousel = new HSCarousel(document.querySelector('#carousel'));
const goTo2Btn = document.querySelector('#go-to-2-btn');
goTo2Btn.addEventListener('click', () => {
carousel.goTo(1);
});
Go to some slide by button click example (mixed).
const carousel = HSCarousel.getInstance('#carousel');
const goTo2Btn = document.querySelector('#go-to-2-btn');
goTo2Btn.addEventListener('click', () => {
carousel.goTo(1);
});
Demo examples
Looking for prebuilt UI components based on the Tailwind CSS? Preline UI packs hundreds of component examples for all your website needs.
Check out Preline UI Components