VaR getxy = function (){
// Determine whether it is IE
If (document.doc umentelement. getboundingclientrect ){
// Note 1
Return function (EL ){
VaR box = El. getboundingclientrect ();
VaR rootnode = El. ownerdocument;
Return [box. Left +
Y. Dom. getdocumentscrollleft (rootnode), box. Top +
Y. Dom. getdocumentscrolltop (rootnode)];
};
} Else {
Return function (EL ){
VaR Pos = [El. offsetleft, El. offsettop];
VaR parentnode = El. offsetparent;
// Determine whether the node is absolute in safari,
// And whether the parent element is body
// Note 2.
VaR accountforbody = (issafari &&
Y. Dom. getstyle (El, 'position') = 'absolute '&&
El. offsetparent = El. ownerdocument. Body );
// If the parent element is not itself
If (parentnode! = El ){
While (parentnode ){
Pos [0] + = parentnode. offsetleft;
Pos [1] + = parentnode. offsettop;
If (! Accountforbody & issafari &&
Y. Dom. getstyle (parentnode, 'position ')
= 'Absolute '){
Accountforbody = true;
}
Parentnode = parentnode. offsetparent;
}
}
// Still for Safari
If (accountforbody) {// safari doubles in this case
Pos [0]-= El. ownerdocument. Body. offsetleft;
Pos [1]-= El. ownerdocument. Body. offsettop;
}
Parentnode = El. parentnode;
// Account for any scrolled ancestors
While (parentnode. tagname &&
! Patterns. root_tag.test (parentnode. tagname ))
{
// Work around opera inline/table scrollleft/top bug
// Note 3.
If (Y. Dom. getstyle (parentnode, 'display ')
. Search (/^ inline | table-row. * $/I )){
Pos [0]-= parentnode. scrollleft;
Pos [1]-= parentnode. scrolltop;
}
Parentnode = parentnode. parentnode;
}
Return Pos;
};
}
} () // Note: executing for loadtime branching note. For the getboundingclientrect method of IE, refer to here.
Note. For details about safari bug, see here.
Note. Refer to the old saying of foreigners (source ):
"-Remove parent scroll unless that parent is inline or a table
To work around und opera inline/table scrollleft/top bug"
Fixed in opera 9.5. (also, opera 9.5 supports getboundingclientrect
And getclientrects.) Finally, for more information about Dom compatibility, see the summary of PPK (how is it true ).