Skip to content
Advertisement

Change JS scrolling event to time interval

I have an image gallery I’m using for a webpage. Currently, the gallery images change when the user scrolls, but I’d like to change it so that the images change on a time interval, and are on a loop instead of an up scroll to go back and a down scroll to go forward. I’m pretty new to Javascript, so I’m now sure how to change the below script from scrolling to timed.

JavaScript

Advertisement

Answer

Just call setInterval, change what happens when navigateDown is called once all pages have been cycled through, and remove the scroll/keydown listeners.

JavaScript
JavaScript
JavaScript
Advertisement