簡體   English   中英

在頁面滾動上加載數據不適用於移動瀏覽器

[英]Load data on page scroll not working in mobile browsers

我在滾動頁面時從db獲取數據。 該代碼適用於桌面瀏覽器,但不適用於移動瀏覽器。

我嘗試了不同的解決方案,但都是徒勞的。

$(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);
                }
            });
        }
    };
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM