Javascript 有人可以规范地区分 scrollTop 和 scrollHeight 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2940006/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can someone canonically differentiate between scrollTop and scrollHeight?
提问by minil
For example,
例如,
function fnCheckScroll(){
var iNewHeight = oDiv.scrollHeight;
var iscrolTop = oDiv.scrollTop;
alert("The value of the scrollHeight property is: " + iNewHeight + "px");
alert("The value of the scrollTop property is: " + iscrolTop + "px");
}
<div id="oDiv" style="overflow: scroll; height= 100px; width= 250px; text-align: left">
Hello<br>
</div>
In IE 8, the value of scrollTop is always: 0 - returns 0 for scrollTop (even after scrolling)?
在 IE 8 中,scrollTop 的值始终为:0 - 为 scrollTop 返回 0(即使在滚动后)?
采纳答案by Matchu
If I scroll down 5px in this window, the window's scrollTopvalue is 5. If I scroll right 10px in a scrollable div, the div's scrollLeftvalue is 10.
如果我在此窗口中向下滚动 5px,则窗口的scrollTop值为 5。如果我在可滚动 div 中向右滚动 10px,则 div 的scrollLeft值为 10。
When I scroll to the top left corner of this window, both its scrollTopand scrollLeftvalues are 0.
当我滚动到这个窗口的左上角时,它的scrollTop和scrollLeft值都是 0。
回答by Tho
回答by Matthew Flaschen
See the MDC articles, scrollTopand scrollHeight. In summary, scrollTop is how much it's currently scrolled, and scrollHeight is the total height, including content scrolled out of view.
请参阅 MDC 文章scrollTop和scrollHeight。综上所述,scrollTop 是当前滚动了多少,scrollHeight 是总高度,包括滚动出视图的内容。
回答by Mike Craig
In Safari 6.0.1 the scrollHeight gives the height of the control and not the total height including content scrolled out of view. So it cannot be used to find the total height required to show without a scroll bar.
在 Safari 6.0.1 中,scrollHeight 给出了控件的高度,而不是包含滚动出视图的内容的总高度。因此它不能用于查找没有滚动条显示所需的总高度。


