How do you get the rendered height of an element?

前端 未结 18 2592
情书的邮戳
情书的邮戳 2020-11-22 03:11

How do you get the rendered height of an element?

Let\'s say you have a

element with some content inside. This content inside is going to st
18条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 03:27

    offsetHeight, usually.

    If you need to calculate something but not show it, set the element to visibility:hidden and position:absolute, add it to the DOM tree, get the offsetHeight, and remove it. (That's what the prototype library does behind the scenes last time I checked).

提交回复
热议问题