That is basically the same workaround I've been using except I just
through it in a div without overflow: auto instead of a table.
Brandon
On 9/26/06, Muskel A <[EMAIL PROTECTED]> wrote:
>
> Hey
>
> Just wondered if there's any decent way of telling a the 'real' width
> of a div with overflow:hidden or auto.
>
> The only method ii found that worked was to create a table in dom
> giving the same width as the div itself putting in the innerHTML and
> then meassuring the width of that table and deleting the table element
> after.
>
> This works in the situations I used it in, but there must be a much
> smoother way doing it.
>
> Code example:
>
> function getRealWidth(id){
>
> //make temp table calc real width of content
> var tmpTable = document.createElement('table');
>
> //set the 'width' of the element set in css or style tag
> tmpTable.width = Element.getDimensions($('tmpTable')).width;
>
> //tmp id
> tmpTable.id = 'tmpTable';
>
>
> //create rest of table
> var tmpTbody = document.createElement('tbody');
> var tmpTr = document.createElement('tr');
> var tmpTd = document.createElement('td');
>
> tmpTd.innerHTML = $(id).innerHTML;
>
> //append
> tmpTr.appendChild(tmpTd);
> tmpTbody.appendChild(tmpTr);
> tmpTable.appendChild(tmpTbody);
>
> //append element to meassure the width
> document.body.appendChild(tmpTable);
>
> var theDim = Element.getDimensions($('tmpTable'));
>
> //remove table element again
> document.body.removeChild(tmpTable);
>
> return theDim.width;
> }
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs
-~----------~----~----~----~------~----~------~--~---