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;
}
}
// It is 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 ).