To calculate a top position for an element of variable height, I was thinking of doing the following:
- Move the element 1000px off the top of the viewport
- Set the element to display: block
- Get the height of the element
- Set the element to display: none
- Continue on as if everything is normal and good
Any pitfalls in this approach? Is there a more elegant solution?
I’d look at prototype’s implementation of
getDimensions.It sets the position to absolute, visibility to hidden, and display to block briefly. I’ve written one which handles getting the height of something which is contained within a
display:noneelement, but it’s a bit shonky in some edge cases.