let currentIndex = 0;
const items = document.querySelectorAll('.carousel-item');
const totalItems = items.length;
const showItem = (index) => {
// Ensure the index is within range
if (index < 0) {
currentIndex = totalItems - 1;
} else if (index >= totalItems) {
currentIndex = 0;
} else {
currentIndex = index;
}
// Move the carousel
const offset = -100 * currentIndex;
const carousel = document.querySelector('#textCarousel');
carousel.style.transform = `translateX(${offset}%)`;
};
// Event listeners for the buttons
document.querySelector('.prev-button').addEventListener('click', () => {
showItem(currentIndex - 1);
});
document.querySelector('.next-button').addEventListener('click', () => {
showItem(currentIndex + 1);
});
// Initial show
showItem(currentIndex);