JavaScript YUI read code Diary of the Yahoo.util.dom-part.4_yui. Ext Related

Source: Internet
Author: User
Tags tagname
var getxy = function () {
To determine if it is IE
if (document.documentElement.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;

To determine if the node is absolute under 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's for Safari.
if (accountforbody) {//safari Doubles in the 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. The Getboundingclientrect method about IE can refer to here.
Note. Safari BUG, see here for details.
Note: Refer to the Foreigner's exact words (provenance).
"-Remove parent scroll unless that parent is inline or a table
To work around Opera inline/table scrollleft/top bug "
Fixed in Opera 9.5. (Also, Opera 9.5 supports Getboundingclientrect
and getclientrects.) Finally, for more DOM compatibility, see PPK's summary (how is he again).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.