【发布时间】:2012-01-03 10:49:30
【问题描述】:
我希望在用户滚动到页面底部时实现内容加载。
我遇到了问题。它在桌面浏览器上运行良好,但在移动设备上却不行。我已经实施了一个肮脏的修复,使它可以在 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
}
})
}
})
【问题讨论】:
-
目标是为移动设备节省带宽吗?
-
不,目前我有一个 javascript 可以检测移动设备的用户代理,并执行某个代码,该代码不是 100%,只能在 iphone 上运行,否则它会执行适用于所有桌面浏览器的普通代码
标签: jquery