I am writing an infinite scroll function and having it run if the $(window).scrollTop()
is almost as large as the documents height, and it works perfectly...
The issue is that it takes a couple seconds for the new posts to load, and in that time, if the page was scrolled, the function was called multiple times before the document got larger and therefore did not load the posts the way I intented.
Can I add a line to a function that will pause a specific event (in this case the scroll
event) until the function has finished executing?
function f(){
//stop $(window).scroll
//execute code
//allow $(window).scroll
}
$(window).scroll(function(){
if(condition){
f();
}
});