php - 在页面滚动上加载数据在移动浏览器中不起作用
问题描述
当我滚动页面时,我正在从数据库中获取数据。该代码在桌面浏览器上运行良好,但在移动浏览器上运行良好。
我从不同的帖子尝试了不同的解决方案,但都是徒劳的。
$(document).ready(function(){
$('body').on('touchmove', onScroll);
$(window).on('scroll', onScroll);
function onScroll(){
var lastID = $('.load-more').attr('lastID');
if(($(window).scrollTop() + window.innerHeight >= document.body.scrollHeight) && (lastID != 0)){
$.ajax({
type:'POST',
url:'getData.php',
data:'Slno='+lastID,
beforeSend:function(){
$('.load-more').show();
},
success:function(html){
$('.load-more').remove();
$('#postList').append(html);
}
});
}
};
});
解决方案
试试这个代码:
$(document).ready(function(){
$('body').on('touchmove', onScroll);
$(window).on('scroll', onScroll);
function onScroll(){
var lastID = $('.load-more').attr('lastID');
if ($(window).scrollTop() > $(document).height() - $(window).height() - 100 && (lastID != 0)) {
$.ajax({
type:'POST',
url:'getData.php',
data:'Slno='+lastID,
beforeSend:function(){
$('.load-more').show();
},
success:function(html){
$('.load-more').remove();
$('#postList').append(html);
}
});
}
};
});
推荐阅读
- python - 如何使用 selenium 在 youtube 中抓取评论 [仅加载 1000 条评论]?
- python - 为什么返回值相同时会出现断言错误?
- java - 更改 pom.xml 后启动 Tomcat 服务器时无法销毁与 ProtocolHandler ["ajp-nio-8009"] 关联的端点
- python-3.x - 我想在我的 pyhton 包中创建一个切换变量来启用/禁用整个包的日志记录
- python - 如何使用Python在excel上打印开始时间和结束时间?
- python - 使用正则表达式只选择子字符串的第二次出现?(Python)
- python - 如何使用正则表达式从 Python 列表中提取括号中的值?
- mapbox - Mapbox gl native 没有渲染所有样式源,导致地图数据丢失
- html - 如何仅更改数字的最后一位数字颜色?
- kubernetes - Red Hat 3scale API Management operator 可以安装在常规(非 OpenShift)Kubernetes 集群中吗