码迷,mamicode.com
首页 > 其他好文 > 详细

获取滚动条距离底部的距离

时间:2018-03-02 14:55:45      阅读:2523      评论:0      收藏:0      [点我收藏+]

标签:scrolltop   color   title   set   pre   charset   pos   console   滚动条   

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>滚动条距离底部的距离</title>
    </head>
    <body>
        <div class="box">
            <div style="height:10000px;"></div>
        </div>
        <script>
            window.addEventListener(scroll,function(){
                console.log(document.documentElement.scrollTop);//代表目前滚动条和最上方的距离多长
                console.log(document.documentElement.scrollHeight);//代表整个滚动条多长
                console.log(document.documentElement.clientHeight);
                console.log(document.documentElement.scrollHeight-document.documentElement.scrollTop-document.documentElement.clientHeight);
            })
        </script>
    </body>
</html>

 

获取滚动条距离底部的距离

标签:scrolltop   color   title   set   pre   charset   pos   console   滚动条   

原文地址:https://www.cnblogs.com/rachelch/p/8492562.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!