6

So todays issue. Working with slideshow functionality with jQuery and setInterval() and things seem to be working as expected.

That is.. until you leave the page for awhile and come back and see a constant fading of images because the intervals appear to be "catching up" with themselves xD

Luckily, setTimeout() takes care of this issue nicely.

Comments
  • 2
    As you noticed neither of both will do the exact timeout specified, it could be a couple of ms more or less, which will result in the exact behavior you described. The difference between the two is that setTimeout() will actually wait, let's say 1000ms and than call the callback and then resets the timeout for another round, while setIntervall waits 1000ms and then executes regardless of if the run before already finished
Add Comment