Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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/

like image 982
waffl Avatar asked Oct 26 '25 13:10

waffl


1 Answers

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

like image 118
Mikhail Avatar answered Oct 29 '25 03:10

Mikhail



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!