Hi,
I've noticed that the getDimensions method changes the elements
position if it display:none is set. Unfortunately this leads to wrong
dimensions in some cases i.E. relative Elements. Why does Prototype
change the position anyway? I don't see the point as changing the
position leads to a wrong clientWidth or clientHeight.
I've overwritten the getDimensions method with the following snippet
thus removing the position change:
Object.extend(Element.Methods,{
getDimensions: function(element) {
element = $(element);
var display = element.getStyle('display');
if (display != 'none' && display != null) // Safari bug
return {width: element.offsetWidth, height:
element.offsetHeight};
// All *Width and *Height properties give 0 on elements
with
display none,
// so enable the element temporarily
var els = element.style;
var originalVisibility = els.visibility;
var originalDisplay = els.display;
els.visibility = 'hidden';
els.display = 'block';
var originalWidth = element.clientWidth;
var originalHeight = element.clientHeight;
els.display = originalDisplay;
els.visibility = originalVisibility;
return {width: originalWidth, height: originalHeight};
}
});
Element.addMethods();
Nothing magic. I've testet this in Firefox 3, IE 6,7,8 and Opera 9.62
successfully so far.
If there is no good reason for the position change it might be useful
to change the getDimensions method a bit. Maybe you could add an
options array containing the temporary display and position settings
which should be used on temporarily enabling the element.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" 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/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---