difference between offsetHeight and clientHeight

前端 未结 2 849
梦毁少年i
梦毁少年i 2020-11-27 09:35

In the javascript dom - what is the difference between offsetHeight and clientHeight of an element?

2条回答
  •  粉色の甜心
    2020-11-27 10:19

    clientHeight:

    Returns the height of the visible area for an object, in pixels. The value contains the height with the padding, but it does not include the scrollBar, border, and the margin.

    offsetHeight:

    Returns the height of the visible area for an object, in pixels. The value contains the height with the padding, scrollBar, and the border, but does not include the margin.

    So, offsetHeight includes scrollbar and border, clientHeight doesn't.

提交回复
热议问题