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
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs
-~----------~----~----~----~------~----~------~--~---
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 <me-Veb2yxRwxBdBDgjK7y7TUQ@public.gmane.org> 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Aren''t the DOM properties scrollHeight and scrollWidth exactly what you need? They should give you the real height and width of the contents of an element - not just the visible contents. I''m not sure about browser compatibility, but it sure seems to work for me in Firefox and IE 7. Niels Leenheer niels.leenheer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---