Javascript jQuery检测滚动到达底部在移动浏览器上不工作
我试图检测用户何时向下滚动网页底部以加载,当用户滚动到接近底部时显示一些内容 我使用了下面的功能,它在所有桌面web浏览器上都能很好地工作,但在移动浏览器上不起作用Javascript jQuery检测滚动到达底部在移动浏览器上不工作,javascript,jquery,html,css,scroll,Javascript,Jquery,Html,Css,Scroll,我试图检测用户何时向下滚动网页底部以加载,当用户滚动到接近底部时显示一些内容 我使用了下面的功能,它在所有桌面web浏览器上都能很好地工作,但在移动浏览器上不起作用 jQuery(function(){ jQuery(document).scroll(function () { if (jQuery(window).scrollTop() + jQuery(window).height() > jQuery(document).height() -100) {
jQuery(function(){
jQuery(document).scroll(function () {
if (jQuery(window).scrollTop() + jQuery(window).height() > jQuery(document).height() -100) {
//show contents
alert('near bottom')
}
});
});
这是我在上面申请的工作网站
当向下滚动显示一些额外的产品时,它可以在普通浏览器上工作,但不能在移动浏览器上工作
有人能帮我解决这个问题吗。我尝试了很多在互联网上的解决方案,但没有成功,谢谢你移动网站与桌面网站不同。原因很简单,边距和填充不同 您的网站可能不知道如何检测在移动设备上运行时发生的更改,因此就web而言,它没有到达底部 你可能需要使用css3,甚至jquery,向web发出信号,表明平台发生了变化,站点现在变小了,页面底部也变小了
至于如何做到这一点,我缺乏建议。但这是总的方向 这是一种适用于所有设备的解决方案:
window.onscroll = function() {
var d = document.documentElement;
var offset = d.scrollTop + window.innerHeight;
var height = d.offsetHeight;
console.log('offset = ' + offset);
console.log('height = ' + height);
if (offset >= height) {
console.log('at the bottom');
}
}
这是解决办法
if ($(window).scrollTop() >= $(document).height() - $(window).height() - 100) {
alert("bottom detected");
}
添加-100以便在移动设备上工作我打开时,您的确切脚本工作正常,请确保其他脚本不会阻止functionality@Mindeater我应用了(typeof window.outerHeight!=“未定义”)?Math.max(window.outerHeight,$(window.height()):$(window.height()但是没有worked@SaumilSoni滚动功能正在工作,但问题是检测页面末尾检测底部并在每个浏览器上加载内容,我认为仍有一种方法可以搜索,该解决方案根本不起作用