Do something 100px before the scrollbar reaches bottom
I have the below Javascript, and the alert shows up as it is supposed to when the scrollbar hits the bottom of the page开发者_高级运维.
However, I would like this to happen 100 pixels before it reaches the bottom. How would I do that?
$(window).scroll(function(){
if($(window).scrollTop() == $(document).height() - $(window).height() ){
alert("at bottom");
}
}
$(window).scroll(function(){
if($(window).scrollTop() + 100 > $(document).height() - $(window).height() ){
alert("at bottom");
}
});
Using >
instead of ==
because the scroll event fires sporadically, so you may scroll past that value a bunch of times without the event ever firing when there's a precise match.
精彩评论