[英]why does my scrollTop for detecting when I scroll to the bottom of the page not work?
我目前正在使用一些js來檢測何時到達所開發網站的頁面底部。 我目前正在使用以下腳本在此測試js:
$(window).scroll(function(){
if ($(window).scrollTop() == $(document).height() - $(window).height() ){
console.log('you are at the bottom');
}
});
我的問題是,僅當我到達滾動頁面的頂部時才會觸發,而不是我想要的效果不理想時才觸發。
誰能看到為什么它不起作用?
謝謝馬克
因為scrollTop是窗口的頂部,所以當您到達頁面的底部時,它並不與底部共線。
您需要考慮窗口高度。
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
alert("bottom!");
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.