1. base.js
    2. function onReachBottom(){
    3. /* 获取滚动区域的高度 */
    4. var dh = document.documentElement.scrollHeight;
    5. var sh = Math.ceil(document.documentElement.scrollTop);
    6. var ah = document.documentElement.clientHeight;
    7. return sh+ah==dh?true:false;
    8. }
    9. <style>
    10. * {
    11. margin: 0;
    12. padding: 0
    13. }
    14. body {
    15. height: 2000px;
    16. background: red;
    17. }
    18. div {
    19. height: 1000px;
    20. background: green;
    21. }
    22. </style>
    23. </head>
    24. <body>
    25. <div>
    26. </div>
    27. <script src="lib/base.js"></script>
    28. <!-- 判断滚动条是否到达底部 -->
    29. <script>
    30. /* 获取滚动区域的高度 */
    31. // var scrollHeight = document.documentElement.scrollHeight;
    32. // console.log(scrollHeight)
    33. // window.onscroll = function(){
    34. // var scrollTop = Math.ceil(document.documentElement.scrollTop);
    35. // var availHeight = document.documentElement.clientHeight;
    36. // if(scrollTop+availHeight == scrollHeight){
    37. // console.log("到达底部")
    38. // }
    39. // }
    40. window.onscroll = function(){
    41. console.log(onReachBottom())
    42. }
    43. </script>

    test.gif