How to know the end of scrolling event for a
tag

前端 未结 3 2017
孤城傲影
孤城傲影 2021-01-02 19:47

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 scrollin         


        
相关标签:
3条回答
  • 2021-01-02 20:27
    $("#page").scroll( function() {
      if($(this)[0].scrollHeight - $(this).scrollTop() == $(this).outerHeight()) {
       // what you want to do ...
      }
    });
    
    0 讨论(0)
  • 2021-01-02 20:33
    $("#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
          }   
    });
    
    0 讨论(0)
  • 2021-01-02 20:40

    Following code worked for me

    $("#page").scroll( function() {
        if($(this).scrollTop() >= ($(this)[0].scrollHeight - $(this).outerHeight())) 
        {
            alert("End here");
        }
    });
    
    0 讨论(0)
提交回复
热议问题