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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With