2013-08-25 97 views
2

我在这里阅读了一些关于如何获得滚动条高度以及“使用百分比”的答案。但最好的方法来计算它没有错误?javascript计算滚动条高度

“错误”是已知的数学,例如,10/15 = 0.666666,这个问题将返回奇怪的滚动条的高度...所以最新最好的办法避免这一点,并获得

高度的百分比=来自scrollHeight的x%?

谢谢。

+0

这些类型的错误。大多数时候,错误足够小,不用担心,尽管 –

回答

-2
$(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 
+0

我认为你理解我的问题。 Firts我不想使用jQuery,第二个滚动条高度不像浏览器高度那么高。 –