javascript 获取html元素的绝对位置...
时间:2010-08-14 来源:baoeni
有时候我们需要知道HTML元素的觉得位置,用ele.offsetTop和ele.offsetLeft只能得到相对位置,这时可以用oElm.getBoundingClientRect
http://msdn.microsoft.com/en-us/library/ms536433%28VS.85%29.aspx
https://developer.mozilla.org/en/DOM/element.getBoundingClientRect
http://www.quirksmode.org/dom/w3c_cssom.html
Returns a TextRectangle object. Each rectangle has four integer properties (top, left, right, and bottom)
that represent a coordinate of the rectangle, in pixels.
the browser calculates all rectangles (see below getClientRects()), and getBoundingClientRect() returns the lowest (top, left) or highest (bottom, right) values found.
相关阅读 更多 +