开发者

Do something 100px before the scrollbar reaches bottom

开发者 https://www.devze.com 2023-03-10 13:17 出处:网络
I have the below Javascript, and the alert shows up as it is supposed to when the scrollbar hits the bottom of the page开发者_高级运维.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消