【问题标题】:window.ScrollHeight and window.ClientHeight are returning the same value in javascriptwindow.ScrollHeight 和 window.ClientHeight 在 javascript 中返回相同的值
【发布时间】:2021-07-24 06:57:50
【问题描述】:

我想使用javascript计算滚动百分比。但由于scrollHeight问题我无法获得。它没有考虑隐藏页面的大小。

Code: https://codepen.io/tmuthu/pen/jOmaKMQ

【问题讨论】:

    标签: javascript html css scroll scrollbar


    【解决方案1】:

    替换

    var topsh = document.documentElement.scrollHeight || document.body.scrollHeight;
    

    var topsh = document.querySelector('.main').scrollHeight
    

    它会起作用的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-08
      • 2015-03-17
      • 2021-11-30
      • 1970-01-01
      • 2020-07-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多