我不明白爲什麼這不起作用。解釋將不勝感激。文檔末尾的事件
var scrollTop = $(window).scrollTop();
var height = $(window).height();
if (scrollTop === height) {
alert("end!");
}
我不明白爲什麼這不起作用。解釋將不勝感激。文檔末尾的事件
var scrollTop = $(window).scrollTop();
var height = $(window).height();
if (scrollTop === height) {
alert("end!");
}
$(window).height()
爲您提供了用戶的視口的大小,總的文件,這是你最有可能想要什麼的不是規模。要查找用戶是否已到達文檔的末尾,您必須查找文檔的大小,編號爲$(document).height()
。
此外,發現如果用戶的到達文件的末尾,使用jQuery,你需要捕獲scroll
事件,看看如果用戶的到達底部:
$(window).scroll(function() {
if ($(window).scrollTop() + $(window).height() === $(document).height()) {
alert("end!");
}
});
有沒有事件處理程序。該代碼只能在頁面加載時運行一次。
$(document).scroll(function() {
// Your code here
});
請注意,該代碼將運行每次滾動的時間,所以不要使其重。
正如別人說,有一些其他的事情錯誤的代碼 - 但把處理程序啓動
如何解釋什麼並不瞭解它的工作,所以我不就得了。開始猜測和建立jsFiddles並挖掘什麼可能不是你的問題? – j08691 2012-03-12 20:31:48