Automatic and Manual slider

How can I let a home slider to play automatically not only manually? This is an example of a slider that I used but there is no example of both playing (manually and automatically) :

Slider demo

What should I add to the JS code? Any help? (Since your original example comes from W3S, have some more W3S.)

Consider what your “next” button does, and how to integrate it into this.

Hi @mileddwaihy, you can schedule showing the next slide using setTimeout()… extending the example from your link:

// Declare a variable to hold the ID of the currently
// scheduled timeout
var scheduled = null;

// ...

function showSlides(n) {
  // ...

  // Clear the currently scheduled timeout so that the timeout
  // resets after manually switching the slides
  // Set a new timeout to show the next slide after a given 
  // amount of time
  scheduled = setTimeout(plusSlides, 5000, 1);

Edit: Whoops, x-post…

Thank you

Thank you for your answer @m3g4p0p

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.