DOM中元素的offsetHeight和scrollHeight之间有什么区别?
在DOM中,元素的 offsetHeight
与其 scrollHeight
之间有什么区别?解释中的图片将是一个很大的帮助。
In the DOM, what is the difference between an element’s offsetHeight
and its scrollHeight
? An image in explanation would be a great help.
HTMLElement.offsetHeight
是包含元素边框,元素垂直填充,元素水平滚动条(如果存在,如果呈现)和元素CSS高度的度量。 HTMLElement.scrollHeight
是衡量元素内容的高度,包括由于溢出而在屏幕上看不到的内容。 HTMLElement.scrollHeight
返回的值将包括padding-top和padding-bottom,但不包括元素边框或元素水平滚动条。
HTMLElement.offsetHeight
is a measurement which includes the element borders, the element vertical padding, the element horizontal scrollbar (if present, if rendered) and the element CSS height.
HTMLElement.scrollHeight
is a measurement of the height of an element's content including content not visible on the screen due to overflow. The value returned by HTMLElement.scrollHeight
WILL include the padding-top and padding-bottom, but will NOT include the element borders or the element horizontal scrollbar.
This page and this page are my sources.
MDN文档还提供了演示的图像。
The MDN documentation also provides images to demonstrate.