I need to measure the offsetHeight of a div that is inside of a hidden element.
-
A workaround is to set the height
to 0
.hidden {
height: 0;
overflow: hidden;
}
Then to get the elements scrollHeight
.
document.querySelector('.hidden').scrollHeight
The scrollHeight will correctly give you the height though the element does not appear. I don't think it affects element flow either.
Example: https://jsfiddle.net/de3vk8p4/7/
Reference: https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/Determining_the_dimensions_of_elements#How_big_is_the_content.3F
讨论(0)