How to check the scroll bar status is already at top or at end?
HTML:
<div id="mydiv" style="overflow: auto; height: 500px"></div>
SCRIPT:
$(document).ready(function()
{
$("#mydiv").scroll(function()
{
var div = $(this);
if (div[0].scrollHeight - div.scrollTop() == div.height())
{
alert("Reached the bottom!");
}
else if(div.scrollTop() == 0)
{
alert("Reached the top!");
}
});
});
check
if($(window).scrollTop() == 0 || $(window).scrollTop() == $(document).height()- $(window).height()) {
// do something
}