detect scroll to bottom of a DIV

2019-07-04 22:18发布

问题:

i want to detect that i reach the bottom of a div my div is 400px height with overflow hidden i don't know the normal height but more than 400px

i'm using this code but it doesn't work any idea?

if($("#article-txt").scrollTop() + $("#article-txt").height() == $("#article-txt")[0].scrollHeight) {
       alert("bottom!");
   }

回答1:

$("#parentdiv").scroll(function(){
    if($(this)[0].scrollHeight - $(this).scrollTop() === $(this).outerHeight()) {
        alert(1);
    };
});

Works. You need to add the parent div name, not the scrolling Div itself.