Search code examples
javascriptslideshow

Javascript and CSS for Automatic Slideshow


I would like to know how to make this slider to automatic slideshow. This slider contains clickable bullets at the bottom and pre/next buttons on the slides but doesn't animate itself.

Would anyone please let me know how to make it automatic slideshow?

https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_slideshow

Thank you in advance.


Solution

  • Use setInterval() function to make the slideshow automatically for the certain time interval. Add the setInterval() function in your example reference link after the below line:

    var slideIndex = 1; showSlides(slideIndex);

    setInterval(function(){ showSlides(++slideIndex); }, 1000);

    The slide will be changed every 1000 milli seconds. If you need you can adjust the time as per your need.