Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: detecting reaching bottom of scroll doesn't work, only detects the top

Tags:

jquery

scroll

So basically my problem is a seemingly simple one.

You can see it in action at http://furnace.howcode.com (please note that data is returned via Ajax, so if nothing happens give it a few moments!).

What's MEANT to happen, is in the second column when you reach the bottom of scrolling, the next 5 results are returned.

But what actually happens is it only returns the 5 results when you hit the TOP of the scroll area. Try it: scroll down, nothing happens. Scroll back up to the top, the results are returned.

What's going wrong?

Here's my code I'm using:

$('#col2').scroll(function(){
    if ($('#col2').scrollTop() == $('#col2').height() - $('#col2').height()){
       loadMore();
    }
});

loadMore(); is the function that gets the data and appends it.

So what's going wrong here? Thanks for your help!

like image 887
Jack Avatar asked May 14 '10 21:05

Jack


1 Answers

The following has been tested, and works fine:

$(window).scroll(function() {
  if ($(window).scrollTop() == $(document).height() - $(window).height()) {
    loadMore();
  }
});
like image 165
Panagiotis Panagi Avatar answered Sep 22 '22 23:09

Panagiotis Panagi