【问题标题】:Check if the scroll is currently at the bottom - no jQuery检查滚动当前是否位于底部 - 没有 jQuery
【发布时间】:2014-11-11 11:35:08
【问题描述】:

不使用jQuery,检查窗口滚动是否位于底部的最简单方法是什么?

我遇到过一些方法,但大多数都不能跨浏览器工作。

【问题讨论】:

标签: javascript html


【解决方案1】:

这是一种适用于我测试过的几种浏览器的技术

window.onscroll = function () {
    var totalHeight = document.documentElement.scrollHeight;
    var clientHeight = document.documentElement.clientHeight;
    var scrollTop = (document.body && document.body.scrollTop)
    ? document.body.scrollTop : document.documentElement.scrollTop;
    if (totalHeight == scrollTop + clientHeight)
        console.log('Bottom');
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-15
    • 2014-11-03
    • 2012-01-03
    相关资源
    最近更新 更多