document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight);

一般情况下,使用 document.body.scrollHeight > window.innerHeight 就可以判断。

但是在 IE7,IE8 中 window.innerHeight 为 underfined,所以为了兼容 IE7、IE8,需要使用 document.documentElement.clientHeight 属性计算窗口高度。

计算滚动条宽度的方法

function getScrollbarWidth() {

    var scrollDiv = document.createElement("div");
    scrollDiv.style.cssText = 'width: 99px; height: 99px; overflow: scroll; position: absolute; top: -9999px;';
    document.body.appendChild(scrollDiv);
    var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
    document.body.removeChild(scrollDiv);

    return scrollbarWidth;

}




参考:https://www.cnblogs.com/nzbin/p/8117535.html

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
  • 2021-08-16
猜你喜欢
  • 2021-11-13
  • 2022-12-23
  • 2022-12-23
  • 2022-03-05
  • 2021-12-10
  • 2022-01-28
  • 2022-12-23
相关资源
相似解决方案