javascript计算滚动条高度

javascript calculating scrollbar height

本文关键字:高度 滚动条 计算 javascript      更新时间:2023-09-26

我在这里读了一些关于如何获得滚动条高度的线程,以及"使用百分比"的答案。但是,在没有错误的情况下计算它的最佳方法是什么?

数学"错误"是已知的,例如10/15=0.666666,这个问题会返回奇怪的滚动条高度。。。那么,避免这种情况的最佳方法是什么,以及获得的百分比

高度=滚动高度的x%?

谢谢。

$(window).height();   // returns height of browser viewport
$(document).height(); // returns height of HTML document
$(window).width();   // returns width of browser viewport
$(document).width(); // returns width of HTML document
screen.height; //for screen height
screen.width; //for screen width

在您的情况下是

$(window).height(); // length y s.bar
$(window).width(); // length x s.bar