I need to admit that I've been frustrated with HTML and CSS "box" model from
the very moment I met it. Why they did not simply implement Knuth's box
model he uses for TeX has always puzzled me. It may be that my exposure to
TeX gave me a (unique) way of thinking about layout because I don't see
others struggling like I do.
The problem I always have is I want to know what I'll call "the real
dimensions". For example, if I have a div that is sticking out past the
right edge of its containing div, getWidth() and any other method I have
tried gives me the size of the containing div and not the real size.
After a long hard struggle several years ago, I came up with these two
functions:
getHeight: function(ele) {
var oldPos = ele.getStyle('position');
ele.setStyle({ position: 'absolute' });
var height = ele.getHeight();
ele.setStyle({ position: oldPos });
return height;
},
getWidth: function(ele) {
var oldPos = ele.getStyle('position');
ele.setStyle({ position: 'absolute' });
var width = ele.getWidth();
ele.setStyle({ position: oldPos });
return width;
},
What this does is it gets the real dimension of the element. For example,
if I have a list of div's for a selection inside another div that has a
fixed width. If one of the lines is too long, how do I figure it out?
Without doing the position: absolute, getWidth returns the width of the
surrounding div even though the div with the text is sticking out to the
right. Also, if another line (inner div) is shorter than the width of the
outer div, it returns the real length of the inner div (when passed the div
of the short line) and that can be used for centering or whatever.
When I saw the announcement for Element.Layout a few months back, I thought
"hey!... they finally are going to give me the real dimensions". But, alas,
that is not the case.
Also, (FYI), if I do the absolute, then get a new layout, then remove the
absolute, the absolute attribute is not "remembered" by the layout element.
i.e. if I get('width') after I remove the absolute attribute, it returns me
the same thing as if I had never done the absolute in the first place. It
is, sorta neat, that I can do the "precompute", and then all the dimensions
are cached.
Am I the only one doing this? It just seems like perhaps a third argument
(boolean) to say "act as if the element is absolute" would be really
valuable.
--
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/prototype-scriptaculous/-/slhOXnzBt20J.
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/prototype-scriptaculous?hl=en.