JavaScript Slider Automatic Slideshow

javascript

(Craita Adelin) #1

Salutare tuturor!

Am si eu o mica problema legat de un slider facut in javascript. Cum as putea adauga acestui script auto sliding?

var slideIndex = 1;
showSlides(slideIndex);

function plusSlides(n) {
  showSlides(slideIndex += n);
}

function currentSlide(n) {
  showSlides(slideIndex = n);
}

function showSlides(n) {
  var i;
  var slides = document.getElementsByClassName("mySlides");
  var dots = document.getElementsByClassName("test");
  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";
}

Am incercat cu setTimeout dar nu am reusit!


(Craita Adelin) #3
setInterval(function() {
    slideIndex++;
    showSlides(slideIndex);
}, 6000)

Am reusit cu aceasta functie.