Are you passing the DOM object to the function, or just the ID??
I stripped your function of all unnecessary stuff, and tried this on a
random page. The only thing I could come up with is that you could try
extending the element before using it, just by passing it through the $
(el) function. This is the safest way to do with any function, so you
can actually pass either an ID of element, the DOM element itself or
an "not-extended element", which was no getDimensions() function.
Also, I find that sometimes dimensions and positioning does not work
while the element is hidden, or a DOM created element not yet appended
to the document (e.i. working on el =
document.createElement(''div'')
before inserting it to the doc)
function CenterElement(el) {
el = $(el);
var dims = el.getDimensions();
console.log(dims);
// writes something like ''Object width=120 height=300''
in
Firefox console log
}
Post more info..
On Nov 16, 1:55 am, michal
<mga...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> does anyone know why Element.getDimensions always returns 0?
>
> i use this code to center an element on the screen...
>
> function CenterElement(el) {
> var windowScroll = GetWindowScroll(el);
> var pageSize = GetPageSize(el);
> var dims = el.getDimensions();
> top = (pageSize.windowHeight - dims.height) / 2;
> top += windowScroll.top;
>
> left = (pageSize.windowWidth - dims.width) / 2;
> left += windowScroll.left;
> // TODO:buggy. zentriert nicht. die grösse des "el" wird
nicht
> ermittelt.
> // kommt immer 0 zurück. Prototype problem?
> el.setStyle({
> top: top + ''px''
> });
> el.setStyle({
> left: left + ''px''
> });
>
> }
>
> the methods GetWindowScroll() GetPageSize() work correctly....
> thanks for any advice. let me know if you need more information
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---