I’ve been messing around with this bit a javascript that I wrote from the ground up and it works fairly well except for one small issue i’ve encountered recently. The purpose of the code is to create a rather simple slideshow that cycles through photos automatically (every 5 seconds).
The issue arose when I added in the functionality to allow a user to select a photo in the series by clicking a link. Now as the user continues clicking through photos the 5 second duration decreases drastically and I can’t figure out what causes it.
I’ve copied all the code needed to recreate and test code to JSFiddle, if anyone cares to take a look and offer some constructive criticism.
Each time the user click those links they start another “round” of
sireTimer(), hence starting anothersetTimeoutso it looks like the time between rotations has shortened when in fact, there are multiple instances of your function firing the rotation functionality.Try adding a flag, to avoid starting addicional
setTimeouts