如何在移动设备上检测到我的文档已到达页面底部?
我有这个代码在桌面设备上完美运行,但不能在移动设备上运行,比如安卓手机,
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
alert("bottom!");
}
});
知道我还应该在代码中包含什么以使其在移动设备上运行吗?
如何在移动设备上检测到我的文档已到达页面底部?
我有这个代码在桌面设备上完美运行,但不能在移动设备上运行,比如安卓手机,
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
alert("bottom!");
}
});
知道我还应该在代码中包含什么以使其在移动设备上运行吗?
我将它用于无限滚动。我几乎在页面底部有一个“加载更多”链接。
jQuery( window ).scroll( function() {
var loadMoreLink = 'a.infinite-link';
var actualLink = jQuery( loadMoreLink );
if ( actualLink.length ) {
var currentPosition = jQuery( loadMoreLink ).offset();
var pixelsVisible = window.innerHeight - currentPosition.top + jQuery( window ).scrollTop();
if ( pixelsVisible > 100 ) {
// time to do some ajax call.
}
}
});