On Apr 22, 7:53 pm, RobG <r...@iinet.net.auwrote:
On Apr 23, 11:41 am, Benjamin Kalytta <bkau...@web.dewrote:
Hi there,
How do I get and set position and size of a html node (certain elements)?
Following will not work for non absolute elements:
document.defaultView.getComputedStyle(element,null ).getPropertyValue("left")
/ getPropertyValue("width") ...
It will return "auto" in certain circumstances.
Using offsetLeft / offsetWidth to get the size and position seems also
not to be the best since values sometimes seems to be incorrect. Setting
control width to offsetWidth will causes the control to get larger than
before.
What is the best way to do this?
Is there any open source javascript "library" (js file) for this purpose?
Have a look at Matt Kruse's position library in his Javascript
Toolbox:
<URL:http://www.javascripttoolbox.com/lib/objectposition/index.php>
Matt's is a good one for position reporting when the page is simple.
My tests showed it doesn't work in all combinations of nested elements
where some of the elements are scrolling, tables, frames, and other
oddities in a wide range of browsers (IE6, O8, S2, FF1.5, I believe).
I haven't seen a library that can do it all. Richard Cornford probably
has some of the most complete knowledge in this area and contests
repeatedly that such a library would be huge.
Peter