原生JS判断页面滚动到底部
//获取滚动条当前的位置   
function getScrollTop() {
    //在标准w3c下,document.body.scrollTop恒为0,需要用document.documentElement.scrollTop来代替;
    var scrollTop = 0;
    if (document.documentElement && document.documentElement.scrollTop) {
        scrollTop = document.documentElement.scrollTop;
    }else if (document.body) {
        scrollTop = document.body.scrollTop;
    }
    return scrollTop;
}

//获取当前可视范围的高度   
function getClientHeight() {
    var clientHeight = 0;
    if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight);
    }else {
        clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
    }
    return clientHeight;
}

//获取文档完整的高度   
function getScrollHeight() {
    return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
}

 

 

图片来源《JavaScript高级程序设计》12.2.3节 元素大小

 

 

声明:本站所有文章和图片,如无特殊说明,均为原创发布。商业转载请联系作者获得授权,非商业转载请注明出处。
真诚赞赏,手留余香
赞赏
随机推荐
WordPress 中如何在主题和插件中使用
p 标签里面不能嵌套块级元素
WordPress 常用的路径
Debian11 安装笔记2:编译安装PHP
MySQL 批量插入数据时如何解决重复问题
Node.js 控制台进度条实现原理
MySQL 批量修改时间
选择排序