Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
07-29-2009, 04:35 PM #1
- Join Date
- Aug 2006
- Thanked 110 Times in 109 Posts
Getting the size that a box would be
Hi. Does anyone know a way of computing the size that a box would be? E.g not actually rendering the box on the page but working out it's dimensions before it is rendered. The reason is my bosses are having me have a text swap script that switches some text when you hover over certain object. I need to find out what the maximum size of box would be for the different texts because that text that is rendered from the start is not necessarily the maximum.
I know i could render them all quickly compute the values then hide them all but i really don't like the idea of hiding content because of search engines guide lines. Anyone know of anything for this kind of thing?You can not say you know how to do something, until you can teach it to someone else.
07-29-2009, 06:04 PM #2
- Join Date
- Nov 2008
- not found
- Thanked 53 Times in 51 Posts
Generate a div, styled: width:1px; height:1px; visibility:hidden; overflow:hidden; position:absolute; left:0; top:0
This element should be able to contain anything at its natural dimensions without disturbing the flow of the document.
Append to the div your generated text container and measure its offsetHeight and offsetWidth.
Remove the container from the div and position it or whatever according to its known size.