我希望在用户滚动到页面底部时实现内容加载。JQuery检测滚动底部
我有问题。它适用于桌面浏览器,但不适用于移动设备。我实施了一个肮脏的修复程序,使其在iPhone上工作,但不是最佳的,因为它不适用于其他大小的移动设备。
我的网站是www.cristianrgreco.com,向下滚动,在行动中看到
问题是添加滚动和高度不等于高度在移动设备上,而他们在桌面浏览器做的效果。
有没有办法检测到移动浏览器?
在此先感谢。
下面是目前正在使用的代码:
$(document).ready(function() {
$(".main").hide().filter(":lt(3)").show();
if ($(document).height() == $(window).height()) {
// Populate screen with content
}
else if (navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i)) {
window.onscroll = function() {
if ($(document).height() - $(window).scrollTop() <= 1278) {
// At the moment only works on iPhone
}
}
}
else {
$(window).scroll(function() {
if ($(window).scrollTop() + $(window).height() >= $(document).height()) {
// Works perfect for desktop browsers
}
})
}
})
是节省带宽的移动设备的目标是什么? – LamonteCristo
不,目前我有一个JavaScript检测移动设备的用户代理,并执行某个代码,该代码不是100%,只能在iphone上工作,否则它会执行在所有桌面上都能正常工作的代码浏览器 – Cristian