简体   繁体   English

Jquery在Scroll Speed上加载更多内容

[英]Jquery Load more on Scroll Speed

I have a little issue with the following code, it's working fine, however, the only problem is that when someone scrolls down a few times while the data has not been loaded, it creates problems such as it loads the same data twice or it skips some part, etc.. Any help would be greatly appreciated to control the speed of this. 我在下面的代码中遇到了一些问题,它运行正常但是,唯一的问题是,当有人在数据未加载时向下滚动几次时,会产生问题,例如它加载相同的数据两次或者它跳过某些部分等等。任何帮助将非常感谢控制这个的速度。

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

A possible solution would be to set a flag on a waypoint. 一种可能的解决方案是在航路点上设置一个标志。

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

This would only fire the loaded data once. 这只会触发一次加载的数据。 This could be fired at waypoints on specific points on the page. 这可以在页面上特定点的路点上触发。

This solved it. 这解决了它。

<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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM