You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
642 B
JavaScript

let currentIndex = 0;
function showSlide(index) {
const slides = document.querySelectorAll('.carousel-item');
if (index >= slides.length) {
currentIndex = 0;
} else if (index < 0) {
currentIndex = slides.length - 1;
} else {
currentIndex = index;
}
const offset = -currentIndex * 100;
document.querySelector('.carousel-inner').style.transform = `translateX(${offset}%)`;
}
function nextSlide() {
showSlide(currentIndex + 1);
}
function prevSlide() {
showSlide(currentIndex - 1);
}
// Optional: Automatically move to the next slide every 3 seconds
setInterval(nextSlide, 8000);