Home > Web Front-end > JS Tutorial > javascript YUI code reading diary YAHOO.util.Dom - Part.4_YUI.Ext related

javascript YUI code reading diary YAHOO.util.Dom - Part.4_YUI.Ext related

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 19:05:44
Original
1154 people have browsed it

var getXY = function() {
// Determine whether it is IE
if (document.documentElement.getBoundingClientRect) {
// Note 1
return function(el) {
var box = el.getBoundingClientRect();

var rootNode = el.ownerDocument; 🎜> Y.Dom.getDocumentScrollTop (rootNode)];
                                                  parentNode = el.offsetParent ; > // Determine whether the node is absolute under Safari,
// Whether the parent element is body
// Note 2.
var accountforBody = > Y.Dom.getStyle(el, 'position') == 'absolute' &&
el.offsetParent == el.ownerDocument.body);

// If the parent element Not itself
if (parentNode != el) {
                                                                                                                                                                                                    ; .offsettop;
y.DOM.GetStyle (Parentnode, 'Position')
== 'Absolute') {
AccountForbody = True;
}
Parentnod e = Parentnode.OffsetParent;
}
         }

            // 还是针对 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
               // 注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注. 有关 IE 的 getBoundingClientRect 方法,可以参考这里。
注. Safari 的 BUG,详细情况参见这里。
注. 参见老外的原话(出处):
"- 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.)最后,有关更多 DOM 的兼容性,可以参看 PPK 的总结(怎么又是他)。

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template