滚动条滚动到底部 | 前端大队长

滚动条滚动到底部

onScroll: function() {
        //取窗口滚动条高度
        var getScrollTop = function() {
            var scrollTop=0;
            if(document.documentElement && document.documentElement.scrollTop) {
                scrollTop = document.documentElement.scrollTop;
            }
            else if(document.body) {
                scrollTop = document.body.scrollTop;
            }
            return scrollTop;
        };
        //取窗口可视范围的高度
        var getClientHeight = function() {
            var clientHeight=0;
            if(document.body.clientHeight && document.documentElement.clientHeight) {
                clientHeight = (document.body.clientHeight<document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;
            } else {
                clientHeight = (document.body.clientHeight>document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;
            }
            return clientHeight;
        };
        //取文档内容实际高度
        var getScrollHeight = function() {
            return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
        };
        //到达底部
        if((getScrollTop()+getClientHeight()+400)>=getScrollHeight()) {
            //console.log('dropDownDisplay')
            ThisPage.dropDownDisplay();
            _hmt.push(['_trackEvent', window.TONGJI_PAGE, 'onscroll',  'DownDisplay' + '_time', new Date().getTime() - window.StartTime]);
        }
},

Latest posts by admin (see all)