The Endless Scroll. Make a fire in front of the bottom

I use this little script to determine if the user scrolls at the bottom

$(window).scroll(function(){

    if($(window).scrollTop() == $(document).height() - $(window).height()){
        if(!taskFired){
            taskFired = true;
            $("#loading_gif").css("display", "block");
            setTimeout(loadMoreMabs, 1500);
        }
    }

});

But I do not want to run the loadMoreMabs function before the bottom is reached. How should I do it? I tried + and - with heights, but it seems like I'm experimenting with something that I really don't understand.

+5
source share
1 answer

What is your question name suggests what you want

Subtract the value from $(document).height()about 50 to start loading 50 pixels from the bottom.

if($(window).scrollTop() <= ($(document).height() - 50) - $(window).height()){

Here is a small demonstration in jsfiddle, I made a dummy function to execute the loadMoreMabs function

http://jsfiddle.net/sg3s/UwXaw/

Fires every time you get close to the bottom and 1500 ms expire.

, ( ).

( - )

http://jsfiddle.net/sg3s/UwXaw/1/

, , >= , , , scrollTop , , ...

+8

All Articles