[英]Jquery Load more on Scroll Speed
我在下面的代碼中遇到了一些問題,它運行正常但是,唯一的問題是,當有人在數據未加載時向下滾動幾次時,會產生問題,例如它加載相同的數據兩次或者它跳過某些部分等等。任何幫助將非常感謝控制這個的速度。
var num = 0;
$(window).scroll(function(){
if ($(window).scrollTop() == $(document).height() - $(window).height()){
num = num + 20;
$.get('load_data.php?load=' + num, function(data){
$('#result').append(data);
});
}
});
一種可能的解決方案是在航路點上設置一個標志。
var flag = false;
var num = 0;
$(window).scroll(function(){
if ($(window).scrollTop() == $(document).height() - $(window).height()){
if(!flag){
num += 20;
$.get('load_data.php?load=' + num, function(data){
$('#result').html(data);
flag = true;
});
}
}
});
這只會觸發一次加載的數據。 這可以在頁面上特定點的路點上觸發。
這解決了它。
<script type='text/javascript'>
var num = 0;
var a = 1;
$(window).scroll(function(){
if ($(window).scrollTop() == $(document).height() - $(window).height()){
if (a == 1) {
a = 2;
num = num + 20;
$.get('load_data.php?url=<?php echo $url; ?>&load=' + num, function(data){
$('#result').append(data);
flag = true;
a = 1;
});
}
}
});
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.