首页 > 其他 > 详细

H5 页面下拉加载更多

时间:2018-04-01 19:26:57      阅读:182      评论:0      收藏:0      [点我收藏+]

 1.html页面:

<body onload="index_roll()">                                                                                                                                        
...                                                                                                                                
</body> 

2.js

<script type="application/javascript">
    //获取滚动条当前的位置
    function  getScrollTop() {
        var scrollTop = 0;
        if (document.documentElement && document.documentElement.scrollTop) {
            scrollTop = document.documentElement.scrollTop;
        }
        else if (document.body) {
            scrollTop = document.body.scrollTop;
        }
        return scrollTop;
    };
//获取当前可是范围的高度 function getClientHeight() { var clientHeight = 0; if (document.body.clientHeight && document.documentElement.clientHeight) { clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight); } else { clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight); } return clientHeight; }; //获取文档完整的高度 function getScrollHeight() { return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight); };

var num=1; //滚动加载 function index_roll(){ window.addEventListener(‘scroll‘, function(){ if (getScrollTop() + getClientHeight() >= (getScrollHeight()-10)) { //要执行的方法 console.log("打印"+num); num++; } }) } </script>

 

H5 页面下拉加载更多

原文:https://www.cnblogs.com/yysbolg/p/8687607.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!