如何知道<div>标记的滚动事件的结束

coo*_*guy 5 javascript jquery scroll

如果滚动结束已到达div标签,我需要触发一个函数.

    $("#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
          }   
    });
Run Code Online (Sandbox Code Playgroud)

Ram*_*din 21

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

  • +1,即使我不得不稍微调整一下`$(this).scrollTop()> = $(this)[0] .scrollHeight - $(this).outerHeight() - 10` ...现在适用于我 :) (3认同)