search

Home  >  Q&A  >  body text

javascript - How to get the height of a height-adaptive element?

The height of my element box is not set and is expanded by the subset content. How to get its height? All methods such as height are 0. Is there any way to get the actual height?

phpcn_u1582phpcn_u15822838 days ago597

reply all(5)I'll reply

  • 習慣沉默

    習慣沉默2017-05-16 13:45:33

    You can delay for a while before getting the height of the content, for example like this

            const oBox=document.getElementById(id);
            setTimeout(function(){
                console.log(oBox.scrollHeight)
            },500)

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-16 13:45:33

    clientHeight, scrollHeight, offsetHeight
    innerHeight, outerHeight
    Basically there is always one that suits you

    reply
    0
  • 某草草

    某草草2017-05-16 13:45:33

    The values ​​obtained are all 0 because the height is not set. What I want is the actual height displayed after the web page is loaded, including subsets

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-05-16 13:45:33

    The first possibility is that js is executed before rendering is completed. . Obtaining 0
    The second possibility is that the child elements are all floating or absolutely positioned. The outermost layer has no height
    The third possibility is that the wrong element is obtained, is the js written wrong?

    reply
    0
  • 怪我咯

    怪我咯2017-05-16 13:45:33

    It should be caused by executing the code to obtain the height before the element is rendered.

    reply
    0
  • Cancelreply