<!DOCTYPE=html>  
<html>  
<head>  
<script src="jquery-1.4.2.min.js" type="text/javascript"></script>  
</head>  
<body>  
    <div>下拉加载更多</div>  
    <div class="main" style="height:700px;overflow:auto;">  
        <div class="child" style='border:1px solid red;margin-top:20px;color:grey;height:800px' ></div>  
    </div>  
</body>  
<script  type="text/javascript">  
$(document).ready(function(){  
    $(".main").unbind("scroll").bind("scroll", function(e){  
        var sum = this.scrollHeight;  
        if (sum <= $(this).scrollTop() + $(this).height()) {  
            $(".main").append($(".child").clone());  
        }  
    });  
});  
</script>  
</html>

  如果等滚动条拉到底部时再加载,会影响用户体验。因为一般动态加载的时候都需要向服务端请求资源,这时需要时间。一个更佳的方式是,当滚动条距离底部一定距离(C)时,就动态加载更多,向服务端请求资源。也就是预加载,预读取。公式如下。

this.scrollHeight - C <= $(this).scrollTop() + $(this).height()  

 

相关文章:

  • 2022-12-23
  • 2021-10-16
  • 2022-02-07
  • 2021-07-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案