js判断已经滚动到页面底部

  js如何判断页面已经滚动到底部

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>js判断已经滚动到页面底部</title>
</head>
<body style="margin:0;padding:0">
    <div id="dvBT" style="position:fixed;bottom:0;right:0;background:#fff"></div>
    <div id="part1" style="height:2000px;overflow: auto;background: lightblue;">
    </div>
    <div id="part2" style="height:3000px;overflow: auto;background:lightcoral;">
    </div>
    <script>
        var viewHeight, scrolllHeight;
        window.onresize = function () {
            viewHeight = document[document.compatMode == 'CSS1Compat' ? 'documentElement' : 'body'].clientHeight;
            scrollHeight = document[document.compatMode == 'CSS1Compat' ? 'documentElement' : 'body'].scrollHeight;
            document.getElementById('dvBT').innerHTML = '<br>scrollHeight:' + scrollHeight + '<br>viewHeight:' + viewHeight;
        }
        window.onresize();
        window.onscroll = function () {
            var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
            document.getElementById('dvBT').innerHTML = (scrollTop + viewHeight >= scrollHeight ? '到达底部' : '') + '<br>scrollTop:' + scrollTop + '<br>scrollHeight:' + scrollHeight + '<br>viewHeight:' + viewHeight;
        }
    </script>
</body>
</html>

 

加支付宝好友偷能量挖...


原创文章,转载请注明出处:js判断已经滚动到页面底部

评论(0)Web开发网
阅读(301)喜欢(0)JavaScript/Ajax开发技巧