Know if the scroll has reached the end of the DIV

3

How do I know that the user rolled the scroll bar from a div to the end? using jquery.

So far I've only been able to do this

scrollTop();

But I do not know how this command can help me

    
asked by anonymous 16.03.2015 / 19:35

1 answer

7

You can do this as follows:

$(document).ready(function(){
    $('div').bind('scroll', function() {
        /*
        * scrollTop -> Quanto rolou
        * innerHeight -> Altura do interior da div
        * scrollHeight -> Altura do conteúdo da div
        */
        if($(this).scrollTop() + $(this).innerHeight() >= this.scrollHeight) {
            $('body').append("<p>Fim da div</p>");
        }
    });
});
div{
    height: 150px;
    width: 80px;
    overflow-y:auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div><p>TESTE</p><p>TESTE</p><p>TESTE</p><p>TESTE</p><p>TESTE</p><p>TESTE</p><p>TESTE</p><p>TESTE</p></div>

Source: SOEN Answer

    
16.03.2015 / 19:50