24 lines
498 B
JavaScript
24 lines
498 B
JavaScript
|
|
const carousel = document.getElementById("carousel");
|
||
|
|
const slides = carousel.querySelectorAll("li");
|
||
|
|
let currentIndex = 0;
|
||
|
|
const intervalTime = 10000;
|
||
|
|
|
||
|
|
function goToSlide(index) {
|
||
|
|
if (index < 0) index = slides.length - 1;
|
||
|
|
if (index >= slides.length) index = 0;
|
||
|
|
|
||
|
|
slides[index].scrollIntoView({
|
||
|
|
behavior: "smooth",
|
||
|
|
inline: "center",
|
||
|
|
block: "nearest"
|
||
|
|
});
|
||
|
|
|
||
|
|
currentIndex = index;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
function nextSlide() {
|
||
|
|
goToSlide(currentIndex + 1);
|
||
|
|
}
|
||
|
|
|
||
|
|
setInterval(nextSlide, intervalTime);
|