I have a scrollable div and when scroll to ‘almost’ bottom then will alert something. (for infinite ajax scroll use)
So here is my code, the code is actually working but ONLY when I paste into Google Chrome console and run it. Not working when I test in ‘real’ scroll. Any idea?
$('.div').scroll(function(){
if ($('.div').scrollTop() + $('.div').height() > $('.lists').height() - 50) {
alert('abc');
}
});
If you are using ajax,
.scrollwill not affect the div because it won’t find it because it doesn’t exist. Instead, delegate with.on: