Using Javascript to detect the bottom of the window and ignoring all events when a request is loading
Posted
by
Aaron Reba
on Stack Overflow
See other posts from Stack Overflow
or by Aaron Reba
Published on 2012-11-28T04:21:06Z
Indexed on
2012/11/28
5:05 UTC
Read the original article
Hit count: 159
JavaScript
I have an anonymous function to detect the user has scrolled to the bottom of the window. Inside of the anonymous function, I have a call to a database that takes a while to complete.
var allowing_more = 1;
$(window).scroll(function() {
if (allowing_more == 1){
if ($(window).scrollTop() + $(window).height() == $(document).height()) {
allowing_more = 0;
//query
allowing_more = 1;
}
}
});
In this time, if the user scrolls to the bottom of the window again, it seems a queue is made holding the occurences the user scrolled to the bottom of the window while the query was loading. Upon completing of the query, these occurences are then executed.
I have a boolean statement to detect if the anonymous function is accepting more query requests but this seems to be ignored.
Is there some sort of way to ignore an anonymous function temporarily and re-enable it?
© Stack Overflow or respective owner