コンテンツへスキップ
const carouselSlide = document.querySelector('.carousel-slide');
const items = document.querySelectorAll('.carousel-item');
const prevButton = document.querySelector('.carousel-prev');
const nextButton = document.querySelector('.carousel-next');
let index = 0;
関数 showItem(index) {
carouselSlide.style.transform = `translateX(${-index * 100}%)`;
}
nextButton.addEventListener('クリック', () => {
index = (index + 1) % items.length;
showItem(index);
});
prevButton.addEventListener('クリック', () => { { index = (index - 1 + items.length)
index = (index - 1 + items.length) % items.length;
showItem(index);
});