dschuett
dschuett

Reputation: 300

Infinite Scroll Is Firing At The Top instead Of Bottom

I have a scroll function that I want to fire when the user scrolls to the very bottom of the page. However it is doing the exact opposite; it is firing at the top of the page. I have used this before, and everything on the web says to do it this same way as well. The only thing I can think of is that it has something to do with using bootstrap. Any ideas? Here is an example: Click Here

 // Load More Results On Scroll
    var busy = false;
    $(window).scroll(function(){
        if($(window).scrollTop() + $(window).height() == $(document).height() && !busy){
            // Currently Fetching Results
            busy = true;

            // Fetch The Rows
            setTimeout(function() {
                $.ajax({
                    url: "../assets/server/public/callbacks.php",
                    type: "POST",
                    dataType: "JSON",
                    data: {
                        filter: '',
                        old_id: $("#old-id").val(),
                        callback: 'selectPreviousTenPosts'
                    },
                    cache: false,
                    success: function(data){
                        $("#feed-wrapper").append(data.post);
                        $("#old-id").val(data.old_id);
                        busy = false;
                    }
                });
            }, 500);
        }
    });

Upvotes: 0

Views: 451

Answers (2)

Ameer A. Lawi
Ameer A. Lawi

Reputation: 83

Try Using Something like this :

$(window).scroll(function() {
   if($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
     alert("near bottom!");
   }
});

Upvotes: 1

bowheart
bowheart

Reputation: 4676

You want to change $(window).height() to window.innerHeight in your if statement:

if($(window).scrollTop() + window.innerHeight >= $(document).height() && !busy){
    //..do stuff
}

Upvotes: 0

Related Questions