原生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节 元素大小

 

 

声明:本站所有文章和图片,如无特殊说明,均为原创发布,转载请注明出处。
随机推荐
JavaScript 操作表单
wp_signon() 自定义用户登录函数
WP_Query 函数参数
HTML input 元素
JavaScript window 对象
如何使主题支持 Woocommerce
URLSearchParams 对象
CSS 基本语法