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

📄 element.js

📁 web2.0完美实现框架
💻 JS
📖 第 1 页 / 共 5 页
字号:
    },    // private	setOverflow : function(v){    	if(v=='auto' && Ext.isMac && Ext.isGecko){ // work around stupid FF 2.0/Mac scroll bar bug    		this.dom.style.overflow = 'hidden';        	(function(){this.dom.style.overflow = 'auto';}).defer(1, this);    	}else{    		this.dom.style.overflow = v;    	}	},	    /**     * Quick set left and top adding default units     * @param {String} left The left CSS property value     * @param {String} top The top CSS property value     * @return {Ext.Element} this     */     setLeftTop : function(left, top){        this.dom.style.left = this.addUnits(left);        this.dom.style.top = this.addUnits(top);        return this;    },    /**     * Move this element relative to its current position.     * @param {String} direction Possible values are: "l","left" - "r","right" - "t","top","up" - "b","bottom","down".     * @param {Number} distance How far to move the element in pixels     * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object     * @return {Ext.Element} this     */     move : function(direction, distance, animate){        var xy = this.getXY();        direction = direction.toLowerCase();        switch(direction){            case "l":            case "left":                this.moveTo(xy[0]-distance, xy[1], this.preanim(arguments, 2));                break;           case "r":           case "right":                this.moveTo(xy[0]+distance, xy[1], this.preanim(arguments, 2));                break;           case "t":           case "top":           case "up":                this.moveTo(xy[0], xy[1]-distance, this.preanim(arguments, 2));                break;           case "b":           case "bottom":           case "down":                this.moveTo(xy[0], xy[1]+distance, this.preanim(arguments, 2));                break;        }        return this;    },    /**     *  Store the current overflow setting and clip overflow on the element - use {@link #unclip} to remove     * @return {Ext.Element} this     */    clip : function(){        if(!this.isClipped){           this.isClipped = true;           this.originalClip = {               "o": this.getStyle("overflow"),               "x": this.getStyle("overflow-x"),               "y": this.getStyle("overflow-y")           };           this.setStyle("overflow", "hidden");           this.setStyle("overflow-x", "hidden");           this.setStyle("overflow-y", "hidden");        }        return this;    },    /**     *  Return clipping (overflow) to original clipping before clip() was called     * @return {Ext.Element} this     */    unclip : function(){        if(this.isClipped){            this.isClipped = false;            var o = this.originalClip;            if(o.o){this.setStyle("overflow", o.o);}            if(o.x){this.setStyle("overflow-x", o.x);}            if(o.y){this.setStyle("overflow-y", o.y);}        }        return this;    },    /**     * Gets the x,y coordinates specified by the anchor position on the element.     * @param {String} anchor (optional) The specified anchor position (defaults to "c").  See {@link #alignTo}     * for details on supported anchor positions.     * @param {Boolean} local (optional) True to get the local (element top/left-relative) anchor position instead     * of page coordinates     * @param {Object} size (optional) An object containing the size to use for calculating anchor position     * {width: (target width), height: (target height)} (defaults to the element's current size)     * @return {Array} [x, y] An array containing the element's x and y coordinates     */    getAnchorXY : function(anchor, local, s){        //Passing a different size is useful for pre-calculating anchors,        //especially for anchored animations that change the el size.        var w, h, vp = false;        if(!s){            var d = this.dom;            if(d == document.body || d == document){                vp = true;                w = D.getViewWidth(); h = D.getViewHeight();            }else{                w = this.getWidth(); h = this.getHeight();            }        }else{            w = s.width;  h = s.height;        }        var x = 0, y = 0, r = Math.round;        switch((anchor || "tl").toLowerCase()){            case "c":                x = r(w*.5);                y = r(h*.5);            break;            case "t":                x = r(w*.5);                y = 0;            break;            case "l":                x = 0;                y = r(h*.5);            break;            case "r":                x = w;                y = r(h*.5);            break;            case "b":                x = r(w*.5);                y = h;            break;            case "tl":                x = 0;                y = 0;            break;            case "bl":                x = 0;                y = h;            break;            case "br":                x = w;                y = h;            break;            case "tr":                x = w;                y = 0;            break;        }        if(local === true){            return [x, y];        }        if(vp){            var sc = this.getScroll();            return [x + sc.left, y + sc.top];        }        //Add the element's offset xy        var o = this.getXY();        return [x+o[0], y+o[1]];    },    /**     * Gets the x,y coordinates to align this element with another element. See {@link #alignTo} for more info on the     * supported position values.     * @param {Mixed} element The element to align to.     * @param {String} position The position to align to.     * @param {Array} offsets (optional) Offset the positioning by [x, y]     * @return {Array} [x, y]     */    getAlignToXY : function(el, p, o){        el = Ext.get(el);        if(!el || !el.dom){            throw "Element.alignToXY with an element that doesn't exist";        }        var d = this.dom;        var c = false; //constrain to viewport        var p1 = "", p2 = "";        o = o || [0,0];        if(!p){            p = "tl-bl";        }else if(p == "?"){            p = "tl-bl?";        }else if(p.indexOf("-") == -1){            p = "tl-" + p;        }        p = p.toLowerCase();        var m = p.match(/^([a-z]+)-([a-z]+)(\?)?$/);        if(!m){           throw "Element.alignTo with an invalid alignment " + p;        }        p1 = m[1]; p2 = m[2]; c = !!m[3];        //Subtract the aligned el's internal xy from the target's offset xy        //plus custom offset to get the aligned el's new offset xy        var a1 = this.getAnchorXY(p1, true);        var a2 = el.getAnchorXY(p2, false);        var x = a2[0] - a1[0] + o[0];        var y = a2[1] - a1[1] + o[1];        if(c){            //constrain the aligned el to viewport if necessary            var w = this.getWidth(), h = this.getHeight(), r = el.getRegion();            // 5px of margin for ie            var dw = D.getViewWidth()-5, dh = D.getViewHeight()-5;            //If we are at a viewport boundary and the aligned el is anchored on a target border that is            //perpendicular to the vp border, allow the aligned el to slide on that border,            //otherwise swap the aligned el to the opposite border of the target.            var p1y = p1.charAt(0), p1x = p1.charAt(p1.length-1);           var p2y = p2.charAt(0), p2x = p2.charAt(p2.length-1);           var swapY = ((p1y=="t" && p2y=="b") || (p1y=="b" && p2y=="t"));           var swapX = ((p1x=="r" && p2x=="l") || (p1x=="l" && p2x=="r"));           var doc = document;           var scrollX = (doc.documentElement.scrollLeft || doc.body.scrollLeft || 0)+5;           var scrollY = (doc.documentElement.scrollTop || doc.body.scrollTop || 0)+5;           if((x+w) > dw + scrollX){                x = swapX ? r.left-w : dw+scrollX-w;            }           if(x < scrollX){               x = swapX ? r.right : scrollX;           }           if((y+h) > dh + scrollY){                y = swapY ? r.top-h : dh+scrollY-h;            }           if (y < scrollY){               y = swapY ? r.bottom : scrollY;           }        }        return [x,y];    },    // private    getConstrainToXY : function(){        var os = {top:0, left:0, bottom:0, right: 0};        return function(el, local, offsets, proposedXY){            el = Ext.get(el);            offsets = offsets ? Ext.applyIf(offsets, os) : os;            var vw, vh, vx = 0, vy = 0;            if(el.dom == document.body || el.dom == document){                vw = Ext.lib.Dom.getViewWidth();                vh = Ext.lib.Dom.getViewHeight();            }else{                vw = el.dom.clientWidth;                vh = el.dom.clientHeight;                if(!local){                    var vxy = el.getXY();                    vx = vxy[0];                    vy = vxy[1];                }            }            var s = el.getScroll();            vx += offsets.left + s.left;            vy += offsets.top + s.top;            vw -= offsets.right;            vh -= offsets.bottom;            var vr = vx+vw;            var vb = vy+vh;            var xy = proposedXY || (!local ? this.getXY() : [this.getLeft(true), this.getTop(true)]);            var x = xy[0], y = xy[1];            var w = this.dom.offsetWidth, h = this.dom.offsetHeight;            // only move it if it needs it            var moved = false;            // first validate right/bottom            if((x + w) > vr){                x = vr - w;                moved = true;            }            if((y + h) > vb){                y = vb - h;                moved = true;            }            // then make sure top/left isn't negative            if(x < vx){                x = vx;                moved = true;            }            if(y < vy){                y = vy;                moved = true;            }            return moved ? [x, y] : false;        };    }(),    // private    adjustForConstraints : function(xy, parent, offsets){        return this.getConstrainToXY(parent || document, false, offsets, xy) ||  xy;    },    /**     * Aligns this element with another element relative to the specified anchor points. If the other element is the     * document it aligns it to the viewport.     * The position parameter is optional, and can be specified in any one of the following formats:     * <ul>     *   <li><b>Blank</b>: Defaults to aligning the element's top-left corner to the target's bottom-left corner ("tl-bl").</li>     *   <li><b>One anchor (deprecated)</b>: The passed anchor position is used as the target element's anchor point.     *       The element being aligned will position its top-left corner (tl) to that point.  <i>This method has been     *       deprecated in favor of the newer two anchor syntax below</i>.</li>     *   <li><b>Two anchors</b>: If two values from the table below are passed separated by a dash, the first value is used as the     *       element's anchor point, and the second value is used as the target's anchor point.</li>     * </ul>     * In addition to the anchor points, the position parameter also supports the "?" character.  If "?" is passed at the end of     * the position string, the element will attempt to align as specified, but the position will be adjusted to constrain to     * the viewport if necessary.  Note that the element being aligned might be swapped to align to a different position than     * that specified in order to enforce the viewport constraints.     * Following are all of the supported anchor positions:<pre>Value  Description-----  -----------------------------tl     The top left corner (default)t      The center of the top edgetr     The top right cornerl      The center of the left edgec      In the center of the elementr      The center of the right edgebl     The bottom left cornerb      The center of the bottom edgebr     The bottom right corner</pre>Example Usage:<pre><code>// align el to other-el using the default positioning ("tl-bl", non-constrained)el.alignTo("other-el");// align the top left corner of el with the top right corner of other-el (constrained to viewport)el.alignTo("other-el", "tr?");// align the bottom right corner of el with the center left edge of other-elel.alignTo("other-el", "br-l?");// align the center of el with the bottom left corner of other-el an

⌨️ 快捷键说明

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