Computed height of element set to display: none

To calculate the top position for a variable height element, I was thinking about doing the following:

  • Move the 1000px element from the top of the viewport.
  • Set displayable element: block
  • Get the height of an element
  • Set displayed item: none
  • Keep driving as if everything is fine and fine

Any pitfalls in this approach? Is there a more elegant solution?

+1


source to share


2 answers


I would take a look at nofollow noreferrer> getDimensions

.



It sets absolute position, visibility to hide, and short-term display. I wrote one that handles the height of something that is contained in an element display:none

, but in some cases with a brief tint.

+3


source


can you just hide the visibility and get the offsetHeight?



0


source







All Articles