getScrollHeight到達底部

weixin_33670713發表於2018-11-26
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>無標題文件</title>
    <style type="text/css">
 *{
            margin:0;
            padding:0;
        }
        body {
            height: 3500px;
        }

        #content {
            background: green;
            margin: 10px;
        }

        div {
            display: none;
        }

    </style>
</head>

<body>
http://www.7160.com/uploads/allimg/140618/9-14061Q11150.jpg<br>
<br><br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br><br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>

<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>

<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
http://www.7160.com/uploads/allimg/140618/9-14061Q11153.jpg
<div id="content" style="width:150px; height:150px; display: block"><img
        realImg="http://www.7160.com/uploads/allimg/140618/9-14061Q11153.jpg" width="150" height="150" src="T85.gif">
</div>
<div id="content" style="width:150px; height:150px; display: block"><img
        realImg="http://www.7160.com/uploads/allimg/140618/9-14061Q11150.jpg" width="150" height="150" src="T85.gif">
</div>
<div id="content" style="width:150px; height:150px; display: block"><img
        realImg="http://img.7160.com/uploads/allimg/140618/9-14061Q11158.jpg" width="150" height="150" src="T85.gif">
</div>
<div id="content" style="width:150px; height:150px; display: block"><img
        realImg="http://img.7160.com/uploads/allimg/140618/9-14061Q11201.jpg" width="150" height="150" src="T85.gif">
</div>
<div id="content" style="width:150px; height:150px; display: block"><img
        realImg="http://img.7160.com/uploads/allimg/140618/9-14061Q11213.jpg" width="150" height="150" src="T85.gif">
</div>

<br>
<br>
<br>
<br>

<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>

<div id="content" style="width:150px; height:150px;"><img
        realImg="http://www.7160.com/uploads/allimg/140618/9-14061Q11153.jpg" width="150" height="150" src="T85.gif">
</div>
<div id="content" style="width:150px; height:150px;"><img
        realImg="http://www.7160.com/uploads/allimg/140618/9-14061Q11150.jpg" width="150" height="150" src="T85.gif">
</div>
<div id="content" style="width:150px; height:150px;"><img
        realImg="http://img.7160.com/uploads/allimg/140618/9-14061Q11158.jpg" width="150" height="150" src="T85.gif">
</div>
<div id="content" style="width:150px; height:150px;"><img
        realImg="http://img.7160.com/uploads/allimg/140618/9-14061Q11201.jpg" width="150" height="150" src="T85.gif">
</div>
<div id="content" style="width:150px; height:150px;"><img
        realImg="http://img.7160.com/uploads/allimg/140618/9-14061Q11213.jpg" width="150" height="150" src="T85.gif">
</div>
<br>
<br>
<br>
<br>

<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>

<div id="content" style="width:150px; height:150px;"><img
        realImg="http://www.7160.com/uploads/allimg/140618/9-14061Q11153.jpg" width="150" height="150" src="T85.gif">
</div>
<div id="content" style="width:150px; height:150px;"><img
        realImg="http://www.7160.com/uploads/allimg/140618/9-14061Q11150.jpg" width="150" height="150" src="T85.gif">
</div>
<div id="content" style="width:150px; height:150px;"><img
        realImg="http://img.7160.com/uploads/allimg/140618/9-14061Q11158.jpg" width="150" height="150" src="T85.gif">
</div>
<div id="content" style="width:150px; height:150px;"><img
        realImg="http://img.7160.com/uploads/allimg/140618/9-14061Q11201.jpg" width="150" height="150" src="T85.gif">
</div>
<div id="content" style="width:150px; height:150px;"><img
        realImg="http://img.7160.com/uploads/allimg/140618/9-14061Q11213.jpg" width="150" height="150" src="T85.gif">
</div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>

<div id="content" style="width:150px; height:150px;"><img
        realImg="http://www.7160.com/uploads/allimg/140618/9-14061Q11153.jpg" width="150" height="150" src="T85.gif">
</div>
<div id="content" style="width:150px; height:150px;"><img
        realImg="http://www.7160.com/uploads/allimg/140618/9-14061Q11150.jpg" width="150" height="150" src="T85.gif">
</div>
<div id="content" style="width:150px; height:150px;"><img
        realImg="http://img.7160.com/uploads/allimg/140618/9-14061Q11158.jpg" width="150" height="150" src="T85.gif">
</div>
<div id="content" style="width:150px; height:150px;"><img
        realImg="http://img.7160.com/uploads/allimg/140618/9-14061Q11201.jpg" width="150" height="150" src="T85.gif">
</div>
<div id="content" style="width:150px; height:150px;"><img
        realImg="http://img.7160.com/uploads/allimg/140618/9-14061Q11213.jpg" width="150" height="150" src="T85.gif">
</div>
<br>

</body>
</html>
<script>
    var utils = {
        getScrollTop: function () {
            var scrollTop = (document.documentElement.scrollTop || document.body.scrollTop) + Math.min(document.body.clientHeight, document.documentElement.clientHeight);
            return scrollTop;
        },
        getScrollHeight: function () {
            //文件的總高度
            var scrollHeight = document.body.scrollHeight;
            return scrollHeight;
        }
    };

    var odivs = document.getElementsByTagName("div");
    var odivslength = 5;
    window.onscroll = function () {
        if (utils.getScrollTop() == utils.getScrollHeight()) {
            alert("到達底部");
            if (odivslength < 20) {
                for (var i = odivslength; i < odivslength + 5; i++) {
                    odivs[i].style.display = "block";
                }
                odivslength += 5;
            }
        }
    }
</script>

<!--

window.onscroll  = function (){
    var marginBot = 0;
    if (document.compatMode === "CSS1Compat"){
        marginBot = document.documentElement.scrollHeight - (document.documentElement.scrollTop+document.body.scrollTop)-  document.documentElement.clientHeight;
    } else {
        marginBot = document.body.scrollHeight - document.body.scrollTop-  document.body.clientHeight;
    }
    if(marginBot<=0) {
        //do something        
    }
}
-->

相關文章