Getboundingclientrect ()
There is a way to quickly obtain the location of web page elements.
That is, use the getboundingclientrect () method. It returns an object, which contains four attributes: Left, right, top, and bottom, which correspond to the distance between the upper left corner and the lower right corner of the element and the upper left corner of the browser window (viewport.
Therefore, the relative position of the webpage element is
VaR x = This. getboundingclientrect (). Left;
Var y = This. getboundingclientrect (). Top;
The absolute position can be obtained by adding the scroll distance.
VaR x = this.getboundingclientrect().left?document.doc umentelement. scrollleft;
Var y javasthis.getboundingclientrect().top?document.doc umentelement. scrolltop;
Currently, ie, Firefox 3.0 +, and opera 9.5 + support this method, whereas Firefox 2.x, safari, chrome, and Konqueror do not.