[英]Load data on page scroll not working in mobile browsers
I am fetching data from db when i scroll the page. 我在滚动页面时从db获取数据。 The code works fine on desktop browsers but not on mobile browsers.
该代码适用于桌面浏览器,但不适用于移动浏览器。
I have tried different solutions from different post but all in vain. 我尝试了不同的解决方案,但都是徒劳的。
$(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);
}
});
}
};
});
Try this code : 试试这段代码:
$(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);
}
});
}
};
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.