0

I am working on a website, which has scroll to BOTTOM to load AJAX content.

I use this Jquery Scroll function:

$(window).scroll(function() { 

  if($(window).scrollTop() + $(window).height() == $(document).height())  
    {

      alert("ScrollTop + Window Height = "+$(window).scrollTop()+ " + " +
      $(window).height()+ " == Document Height = "+$(document).height());

      // This get's alerted only when i reach TOP
    }

  });

But this works only if i reach TOP

Do anyone had this problem before ?

3 Answers3

0

You can try following code for your issue.

$(window).scroll(function() {
    if($(window).scrollTop() == $(document).height() -$(window).height())     
    {
       load_data(); 
    }
});

And for more information visit this Link

Community
  • 1
  • 1
Divyesh Patoriya
  • 518
  • 3
  • 15
0

First you need to understand defference between window and document for example 800wX600h ($(window).scrollTop() + $(window).height() == $(document).height()

0+600=600

So it should be 0+600 > 600

replace it with ($(window).scrollTop() + $(window).height() == $(document).height()

Vinayak Shedgeri
  • 2,222
  • 1
  • 21
  • 24
0

I found a solution for this issue,

Its My Mistake that, i didn't include doc type in my html code.

<!DOCTYPE html>

And that's why the scroll worked in reverse order. After including the doctype at the 1st line of the code, it's working good as expected (i.e) Scrolling to the bottom of page to load more AJAX content or call function().

So when ever you write a code start with < !DOCTYPE html >