setInterval and clearInterval in JavaScript

Recently I was working on an image slider that I had auto-rotating by using setInterval and clearInterval. The problem I came across was that when a user clicks to show another slider image, the counter variable wasn’t resetting. For example, if image 3 was showing, and the user clicked image 6… 6 would show, then 4 would show after, then 5 and so on. So I decided to dive deeper into my investigation of setInterval and share my findings!

Playing with JavaScript setInterval/clearInterval

I hope this jsfiddle is helpful in seeing how setInterval works. Let me know if there’s anything specific you’d like me to talk about in my next Snippet Sunday.

Update – 4/10/17
I just discovered this when Googling for setInterval.

Was this post helpful?