⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 element.js

📁 javascript 很酷的类库
💻 JS
📖 第 1 页 / 共 5 页
字号:
    } else {        // debug message for sanity checking coordinate caching        //this.logWarn(element.getAttribute("eventProxy") + ": new DOM value for offsetLeft");    }    // always subtract the left margin (if there is one) to get the position OUTSIDE the    // margins.    // Note: for a negative margin, the reported offsetLeft does not need to be adjusted by the    // specified margin size - it represents the position of the element - and in this case there    // is no margin outside the element (rather the specified margin shifts the element to the     // left / up)    var leftMargin = parseInt(isc.Element.getComputedStyleAttribute(element, "marginLeft"));    if (isc.isA.Number(leftMargin) && leftMargin > 0) {        left -= leftMargin;    }            var documentBody = this.getDocumentBody(),        parentStyle,        px = "px",        // determine whether the element is absolutely / relatively / etc. positioned            elementPosition = element.style.position;    // Workarounds for Moz            if (isc.Browser.isMoz) {        // In moz we get some unexpected results                if (element.offsetParent == null) return left;                if (element.offsetParent != documentBody) {            parentStyle =                 this.ns.Element.getComputedStyle(element.offsetParent, ["borderLeftWidth", "overflow"]);                   // The behavior changes with different releses of Moz / Firefox            var geckoVersion = isc.Browser.geckoVersion,                                            scrollingAdjustment = (parentStyle.overflow != "visible") &&                                      (geckoVersion >= 20051111 ||                                       (elementPosition == isc.Canvas.ABSOLUTE && parentStyle.overflow != "hidden")),                                accountForBorderBox = (geckoVersion > 20020826 &&                                        (element.offsetParent.style.MozBoxSizing == "border-box"));                        if (accountForBorderBox != scrollingAdjustment) {                                if (accountForBorderBox) {                    left -= (isc.isA.Number(parseInt(parentStyle.borderLeftWidth)) ?                                            parseInt(parentStyle.borderLeftWidth) : 0);                                                            }                                 if (scrollingAdjustment) {                    left += (isc.isA.Number(parseInt(parentStyle.borderLeftWidth)) ?                                            parseInt(parentStyle.borderLeftWidth) : 0);                                                            }            }                          }    }        // Workarounds for IE    if (isc.Browser.isIE) {                    var currentParent = element.offsetParent,            parentStyle;        if (parentStyle != documentBody) parentStyle = currentParent.currentStyle;                         var hasSpecifiedSize = (element.currentStyle.height != isc.Canvas.AUTO ||                                element.currentStyle.width != isc.Canvas.AUTO);                var continueDeductingBorders = true;                                                // iterate up the offsetParents till we reach the doc. body        while (currentParent != documentBody) {                                                if (parentStyle.position == isc.Canvas.ABSOLUTE) continueDeductingBorders = false;                                    if (parentStyle.width == isc.Canvas.AUTO &&                 parentStyle.height == isc.Canvas.AUTO &&                parentStyle.position == isc.Canvas.RELATIVE) {                                                if (continueDeductingBorders &&                    isc.isA.String(parentStyle.borderLeftWidth) &&                     parentStyle.borderLeftWidth.contains(px)        ) {                        left -= parseInt(parentStyle.borderLeftWidth);                }                                                    if (hasSpecifiedSize) {                                    if (isc.isA.String(parentStyle.marginLeft) &&                         parentStyle.marginLeft.contains(px))                     {                        var parentMarginLeft = parseInt(parentStyle.marginLeft);                        if (parentMarginLeft > 0) left -= parentMarginLeft;                    }                                                                                   if (currentParent.offsetParent != documentBody) {                                                   var superPadding = currentParent.offsetParent.currentStyle.padding;                        if (isc.isA.String(superPadding) && superPadding.contains(px)) {                            left -= parseInt(superPadding);                        }                    } else {                                                    left -= (documentBody.leftMargin ? parseInt(documentBody.leftMargin) : 0);                                    }                }                             } // end of if                        elementPosition = currentParent.style.position;            currentParent = currentParent.offsetParent;            if (currentParent != document.body) {                parentStyle = currentParent.currentStyle;            }                    }   // End of while loop            }                // Workarounds for Safari    if (isc.Browser.isSafari) {        // In Safari, if the offsetParent has a border, the offsetLeft / top reported is         // relative to the outside of that border, rather than the inside, so deduct that value        if (element.offsetParent != null && element.offsetParent != documentBody) {            var parentBorder =                 this.ns.Element.getComputedStyle(element.offsetParent, ["borderLeftWidth"]).borderLeftWidth;            if (parentBorder != null) parentBorder = parseInt(parentBorder);            if (isc.isA.Number(parentBorder)) left -= parentBorder;        }    }    // --- cacheing code:    // Cache the calculated and reported value, by saving it as attributes on the DOM element    element._cachedReportedOffsetLeft = element.offsetLeft;    element._cachedCalculatedOffsetLeft = left;        return left;},// Element.getOffsetTop()//  Takes 'element' //  element should be a pointer to a DOM element or the ID for a DOM element (doesn't //  handle getting a widget ID - in that case use widget.getOffsetTop() instead)//  Returns the true offsetTop - the absolute top coordinate with respect to (the inside of any//  border of) whatever is reported by the DOM as the offsetParent of the element.getOffsetTop : function (element) {    // In theory the value element.offsetTop should be what we want here. However it is    // unreliable in a number of ways.    if (element == null) {        this.logWarn("getOffsetTop: passed null element");        return 0;    }        // IE and Moz both return somewhat unreliable values for element.offsetTop by default.    // Paper over these bugs and differences.    var top = element.offsetTop;  // This is what we'd return if the browsers worked correctly!        // --- caching code:    // If we've already calculated a value (based on a reported offsetTop value), and    // the reported value has not changed, return the previously calculated value.    if (element._cachedReportedOffsetTop == top) {                return element._cachedCalculatedOffsetTop;    } else {        // debug message for sanity checking coordinate caching        //this.logWarn(element.getAttribute("eventProxy") + ": new DOM value for offsetTop");    }    // The reported offsetTop is the offset from the element, INSIDE of margins to the    // offsetParent - if we have a top margin we should subtract it to get the position OUTSIDE    // the margins.    // Exception: If the margin is negative, we don't need to adjust for it. In this case the    // reported offset is still to the outside of the element, even though the element is     // essentially shifted above where it would normally appear.        var topMargin = parseInt(isc.Element.getComputedStyleAttribute(element, "marginTop"));    if (isc.isA.Number(topMargin) && topMargin > 0) {        top -= topMargin;    }        var documentBody = this.getDocumentBody(),        parentStyle,        px = "px",        elementPosition = element.style.position;    // Workarounds for Moz            if (isc.Browser.isMoz) {                                if (element.offsetParent == null) return top;        if (element.offsetParent != documentBody) {            // get the offsetParent's style info            parentStyle = this.ns.Element.getComputedStyle(element.offsetParent, ["overflow", "borderTopWidth"]);            var scrollingAdjustment = (parentStyle.overflow != "visible") &&                                       (isc.Browser.geckoVersion >= 20051111 ||                                       (elementPosition == isc.Canvas.ABSOLUTE && parentStyle.overflow != "hidden")),                            accountForBorderBox = (isc.Browser.geckoVersion > 20020826 &&                                         element.offsetParent.style.MozBoxSizing == "border-box");                        if (accountForBorderBox != scrollingAdjustment) {                if (accountForBorderBox) {                    top -= (isc.isA.Number(parseInt(parentStyle.borderTopWidth)) ?                                            parseInt(parentStyle.borderTopWidth) : 0);                }                 if (scrollingAdjustment) {                    top += (isc.isA.Number(parseInt(parentStyle.borderTopWidth)) ?                                            parseInt(parentStyle.borderTopWidth) : 0);                }               }        }    }        // Workarounds for IE    if (isc.Browser.isIE) {                if (element.offsetParent && element.offsetParent != documentBody) {            parentStyle = element.offsetParent.currentStyle;                                      if (    parentStyle.position == isc.Canvas.RELATIVE &&                      parentStyle.height == isc.Canvas.AUTO &&                     parentStyle.width == isc.Canvas.AUTO &&                      isc.isA.String(parentStyle.borderTopWidth) &&                     parentStyle.borderTopWidth.contains(px)         ) {                        top -= parseInt(parentStyle.borderTopWidth);            }        }    }            // Workarounds for Safari    if (isc.Browser.isSafari) {        // As noted in 'getOffsetLeft()', in Safari the width of the parent's border is included        // in the offsetLeft/top value reported.        if (element.offsetParent && element.offsetParent != documentBody) {            var parentBorder =                 this.ns.Element.getComputedStyle(element.offsetParent,                                                 ["borderTopWidth"]).borderTopWidth;                        if (parentBorder != null) parentBorder = parseInt(parentBorder);            if (isc.isA.Number(parentBorder)) top -= parentBorder;        }    }            // --- cacheing code:    // Cache the calculated and reported value, by saving it as attributes on the DOM element    element._cachedReportedOffsetTop = element.offsetTop;    element._cachedCalculatedOffsetTop = top;       return top;},// _getLeftOffsetFromElement(element, targetElement, rtl)//// DOM Only method to return the absolute (offset) position for some element within some other // DOM parent element.  We will return this value from the outside of any border / margin on// the child to the inside of the ancestor element.//_getLeftOffsetFromElement : function (element, targetElement, rtl) {    return this._getOffsetFromElement(isc.Canvas.LEFT, element, targetElement, rtl);},// Return the absolute position of an element within a DOM parent element.// If no target parent element is passed, we return page level position._getTopOffsetFromElement : function (element, targetElement) {    return this._getOffsetFromElement(isc.Canvas.TOP, element, targetElement);},_$borderLeftWidth : isc.Browser.isMoz ? "border-left-width" : "borderLeftWidth",_$borderTopWidth : isc.Browser.isMoz ? "border-top-width" : "borderTopWidth",_$marginLeft : isc.Browser.isMoz ? "margin-left" : "marginLeft",_$marginTop : isc.Browser.isMoz ? "margin-top" : "marginTop",_$none:"none",_getOffsetFromElement : function (dir, element, targetElement, rtl) {    //!DONTCOMBINE    //>DEBUG    if (targetElement == null || element == null) {        this.logWarn("Element._getOffsetFromElement passed bad parameters - returning 0");        return 0;    }    //<DEBUG    var nextParent = element.offsetParent;        if (isc.Browser.isMoz && nextParent == null) return 0;            // To get the offsetLeft / Top with respect to the passed in targetElement,         // iterate through the offsetParents, summing 'offsetLeft' until we reach the targetElement.    // If we reach the targetElement's offsetParent before we hit the targetElement we've jumped    // over the target - this is Ok - just deduct the offsetLeft of the targetElement to adjust    // for it.    // For each iteration adjust for scrolling and border / margin thickness     // (see comments in the while loop below).    var targetParent = targetElement.offsetParent,        currentNode = element,        offset = 0,        isLeft = (dir == isc.Canvas.LEFT),        borderWidthProp = (isLeft ? this._$borderLeftWidth : this._$borderTopWidth),        marginProp = (isLeft ? this._$marginLeft : this._$marginTop);      if (!isLeft) rtl = false;    else if (rtl == null) rtl = (isc.Page.getTextDirection() == isc.Canvas.RTL);    // iterate up until we reach the targetElement, or the targetElement's offsetParent

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -