我有以下Javascript,当滚动条点击页面底部时,警报会显示出来。
但是,我希望在到达底部之前发生100像素。我该怎么办?
$(window).scroll(function(){
if($(window).scrollTop() == $(document).height() - $(window).height() ){
alert("at bottom");
}
}
答案 0 :(得分:9)
$(window).scroll(function(){
if($(window).scrollTop() + 100 > $(document).height() - $(window).height() ){
alert("at bottom");
}
});
使用>
代替==
因为滚动事件偶尔会触发,因此您可以多次滚动该值,而不会在精确匹配时触发事件。