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?
習慣沉默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)
大家讲道理2017-05-16 13:45:33
clientHeight, scrollHeight, offsetHeight
innerHeight, outerHeight
Basically there is always one that suits you
某草草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
给我你的怀抱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?
怪我咯2017-05-16 13:45:33
It should be caused by executing the code to obtain the height before the element is rendered.