6

I need to trigger a function if scroll end has reached for a div tag ..

    $("#page").bind("scroll",function(e){ //page is the ID of the div im scrolling
          if (document.body.scrollHeight - $(this).scrollTop()  <= $(this).height())
          {
             //the code here is called every time the scroll is happened i want to call     
             //this only when the scroll reaches the end of div
          }   
    });
karim79
  • 339,989
  • 67
  • 413
  • 406
coolguy
  • 7,866
  • 9
  • 45
  • 71

3 Answers3

23
$("#page").scroll( function() {
  if($(this)[0].scrollHeight - $(this).scrollTop() == $(this).outerHeight()) {
   // what you want to do ...
  }
});
PiTheNumber
  • 22,828
  • 17
  • 107
  • 180
Ramiz Uddin
  • 4,249
  • 4
  • 40
  • 72
  • 4
    +1, even though I had to tweak it a little `$(this).scrollTop() >= $(this)[0].scrollHeight - $(this).outerHeight() - 10` ... now works to me :) – Ish Dec 07 '12 at 17:28
2
$("#page").bind("scroll",function(e){ //page is the ID of the div im scrolling

      if ( ( $(this).height() + $(this).scrollTop() ) => $(this).innerHeight() )
      {
         //Test it first without padding. Then see if you need to tweak the left part of the condition
      }   
});
Z. Zlatev
  • 4,757
  • 1
  • 33
  • 37
1

Following code worked for me

$("#page").scroll( function() {
    if($(this).scrollTop() >= ($(this)[0].scrollHeight - $(this).outerHeight())) 
    {
        alert("End here");
    }
});
Kedar
  • 21
  • 6