Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know the end of scrolling event for a <div> tag

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
          }   
    });
like image 818
coolguy Avatar asked Nov 22 '10 11:11

coolguy


2 Answers

$("#page").scroll( function() {
  if($(this)[0].scrollHeight - $(this).scrollTop() == $(this).outerHeight()) {
   // what you want to do ...
  }
});
like image 164
Ramiz Uddin Avatar answered Oct 04 '22 12:10

Ramiz Uddin


$("#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
      }   
});
like image 45
Z. Zlatev Avatar answered Oct 04 '22 12:10

Z. Zlatev