zoukankan      html  css  js  c++  java
  • 滚动加载数据

    function scrollLoad() {
            var ele = document.getElementById('mainListBlock');
            var isLastPage = false;
            window.isLoading = false;
            var clientHeight = getClientHeight();
    
            function getScrollTop() {
                return ele.scrollTop;
            }
            function getScrollHeight() {
                return ele.scrollHeight;
            }
            function getClientHeight() {
                var clientHeight = 0;
                if (document.body.clientHeight && document.documentElement.clientHeight) {
                    clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight) + 110;
                }
                else {
                    clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight) + 110;
                }
                return clientHeight;
            }
            function reachBottom() {
                var scrollTop = getScrollTop();
                var scrollHeight = getScrollHeight();
                /*console.log('页面顶端滚动距离' + scrollTop);
                 console.log('窗口高度' + clientHeight);*/
                //console.log('距离底部距离' + (scrollHeight - scrollTop - clientHeight));
    
                return (scrollTop + clientHeight == scrollHeight) ? true : false;
            }
            function handleTouch(e) {
                switch(e.type) {
                    case 'touchstart':
                        //console.log('touch start');
                        break;
                    case 'touchmove':
                        //console.log('touch move');
                        //如果到达页面低部,则出现提示:松开加载更多,
                        /*if (reachBottom()) {
                         e.preventDefault();
                         }*/
                        break;
                    case 'scroll':
                        //console.log('scroll');
                        if (reachBottom() && window.pageCount - window.pageNo > 0 && !window.isLoading) {
                            console.log(window.pageCount - window.pageNo);
                            window.pageNo++;
                            //console.log('load more data');
                            window.isLoading = true;//避免重复加载
                            loadGoodsList(window.pageNo);
                        }
                        break;
                }
            }
            ele.addEventListener('touchstart', handleTouch);
            ele.addEventListener('touchmove', handleTouch);
            ele.addEventListener('scroll', handleTouch);
        }
  • 相关阅读:
    javascript获取url参数的代码
    SharePoint最简母版页
    添加 <identity impersonate="true" userName="username" password="password"/>,解决问题!
    使用SPD自定义MOSS导航
    浮动图标代码
    十五种网站最差的用户体验
    div flash firefox div层总是被flash层遮盖
    压缩数据库扩展名为.ldf的日志文件
    版本的签入签出策略
    用CSS制作的圆角层
  • 原文地址:https://www.cnblogs.com/flyfly/p/4836212.html
Copyright © 2011-2022 走看看