Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
692 B
2
Indexable
Never
const carousel = document.querySelector('.carousel');
const slides = carousel.querySelectorAll('.slide');
//const prevBtn = document.querySelector('.prev-btn');
const nextBtn = document.querySelector('.next-btn');

let currentSlide = 0;

nextBtn.addEventListener('click', () => {
  currentSlide = (currentSlide + 1) % slides.length;
  updateCarousel();
  nextBtn.classList.toggle('red');
});

/*prevBtn.addEventListener('click', () => {
  currentSlide = (currentSlide - 1 + slides.length) % slides.length;
  updateCarousel();
});*/

function updateCarousel() {
  const transformValue = `translateX(-${currentSlide * 100}%)`;
  carousel.style.transform = transformValue;
}