Javascript - Possible to check if an interval is already set?

waffl picture waffl · Oct 31, 2011 · Viewed 9.3k times · Source

I have a div that is bouncing every 5 seconds using an interval.

When scrolling to the bottom of the page, this div fades out and the interval is cleared.

However, I think there is an issue with the interval being created multiple times and overlaps upon itself.

Is there a way to check if an interval is set, and if so clear it, and if not, to set it?

The reason I need to clear the interval is because the bounce effect of jquery causes the div to appear again even if it's hidden.

JSBIN: http://jsbin.com/ijuhok/4/

Answer

Mikhail picture Mikhail · Oct 31, 2011

Seems that you set the interval whenever it is scrolled. So if I scroll down, and then scroll down again you set it twice.

Just clear it before hand every time you set it and you should be ok.

http://jsbin.com/ijuhok/6