• Как сделать автоматический слайдер на JavaScript?

    @EvgeniyKhmara
    let autoplayInterval = null;

    function startAutoplay() {
    if (!autoplayInterval) {
    autoplayInterval = setInterval(nextSlide, 1000);
    }
    }

    function stopAutoplay() {
    clearInterval(autoplayInterval);
    autoplayInterval = null;
    }

    startAutoplay();

    dots.forEach((item, indexDot) => {
    item.addEventListener('click', () => {
    index = indexDot;
    prepareCurrentSlide();
    stopAutoplay();
    })
    });

    const nextSlide = () => {
    if(index == slides.length - 1) {
    index = 0;
    prepareCurrentSlide();
    }else {
    index++;
    prepareCurrentSlide();
    }
    startAutoplay();
    }
    Ответ написан
    Комментировать