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
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
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