JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0/dist/carousel/carousel.css"
/>
<style>
#myCarousel {
--f-carousel-spacing: 10px;
--f-carousel-slide-width: 60%;
}
#myCarousel .f-carousel__slide {
padding: 50px;
background: #eee;
}
</style>
</head>
<body>
<div>
<div class="f-carousel" id="myCarousel">
<div class="f-carousel__slide">#1</div>
<div class="f-carousel__slide">#2</div>
<div class="f-carousel__slide">#3</div>
</div>
<p>
<button id="addSlide">Add new slide at index: 2</button>
<button id="prependSlide">Prepend new slide</button>
<button id="appendSlide">Append new slide</button>
</p>
</div>
<script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0/dist/carousel/carousel.umd.js"></script>
<script>
const myCarousel = new Carousel(document.getElementById("myCarousel"), {
//
});
document.getElementById("addSlide").addEventListener("click", () => {
myCarousel.addSlide(2, {
html: `Added slide in third position #${myCarousel.slides.length + 1}`,
});
});
document.getElementById("prependSlide").addEventListener("click", () => {
myCarousel.prependSlide({
html: `Added a slide at the start #${myCarousel.slides.length + 1}`,
});
});
document.getElementById("appendSlide").addEventListener("click", () => {
myCarousel.appendSlide({
html: `Added a slide at the end #${myCarousel.slides.length + 1}`,
});
});
</script>
</body>
</html>