How to know the end of scrolling event for a

2019-02-10 08:56发布

问题:

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
          }   
    });

回答1:

$("#page").scroll( function() {
  if($(this)[0].scrollHeight - $(this).scrollTop() == $(this).outerHeight()) {
   // what you want to do ...
  }
});


回答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
      }   
});


回答3:

Following code worked for me

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