...

View Full Version : Getting the size that a box would be



timgolding
07-29-2009, 03:35 PM
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?

randomuser773
07-29-2009, 05:04 PM
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. Unless someone knows a simpler way, this is what i would try.

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.

No.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum