P
P
pankratov_tolik2018-03-13 17:51:44
JavaScript
pankratov_tolik, 2018-03-13 17:51:44

How to make this autoplay slider?

var slideIndex = 1;
showSlides(slideIndex);

// Next/previous controls
function plusSlides(n) {
  showSlides(slideIndex += n);
}

// Thumbnail image controls
function currentSlide(n) {
  showSlides(slideIndex = n);
}

function showSlides(n) {
  var i;
  var slides = document.getElementsByClassName("mySlides");
  var dots = document.getElementsByClassName("dot");
  if (n > slides.length) {slideIndex = 1} 
  if (n < 1) {slideIndex = slides.length}
  for (i = 0; i < slides.length; i++) {
      slides[i].style.display = "none"; 
  }
  for (i = 0; i < dots.length; i++) {
      dots[i].className = dots[i].className.replace(" active", "");
  }
  slides[slideIndex-1].style.display = "block"; 
  dots[slideIndex-1].className += " active";
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Gorelov, 2018-03-14
@Kirill-Gorelov

The simplest option that comes to mind is to put setTimeOut on the function function plusSlides(n) {
showSlides(slideIndex += n);
}
Is she the one flipping through the slides?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question