📄 element.js
字号:
return cs[camel]; } return null; }; }(), /** * Wrapper for setting style properties, also takes single object parameter of multiple styles. * @param {String/Object} property The style property to be set, or an object of multiple styles. * @param {String} value (optional) The value to apply to the given property, or null if an object was passed. * @return {Ext.Element} this */ setStyle : function(prop, value){ if(typeof prop == "string"){ var camel; if(!(camel = propCache[prop])){ camel = propCache[prop] = prop.replace(camelRe, camelFn); } if(camel == 'opacity') { this.setOpacity(value); }else{ this.dom.style[camel] = value; } }else{ for(var style in prop){ if(typeof prop[style] != "function"){ this.setStyle(style, prop[style]); } } } return this; }, /** * More flexible version of {@link #setStyle} for setting style properties. * @param {String/Object/Function} styles A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or * a function which returns such a specification. * @return {Ext.Element} this */ applyStyles : function(style){ Ext.DomHelper.applyStyles(this.dom, style); return this; }, /** * Gets the current X position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). * @return {Number} The X position of the element */ getX : function(){ return D.getX(this.dom); }, /** * Gets the current Y position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). * @return {Number} The Y position of the element */ getY : function(){ return D.getY(this.dom); }, /** * Gets the current position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). * @return {Array} The XY position of the element */ getXY : function(){ return D.getXY(this.dom); }, /** * Returns the offsets of this element from the passed element. Both element must be part of the DOM tree and not have display:none to have page coordinates. * @param {Mixed} element The element to get the offsets from. * @return {Array} The XY page offsets (e.g. [100, -200]) */ getOffsetsTo : function(el){ var o = this.getXY(); var e = Ext.fly(el, '_internal').getXY(); return [o[0]-e[0],o[1]-e[1]]; }, /** * Sets the X position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). * @param {Number} The X position of the element * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object * @return {Ext.Element} this */ setX : function(x, animate){ if(!animate || !A){ D.setX(this.dom, x); }else{ this.setXY([x, this.getY()], this.preanim(arguments, 1)); } return this; }, /** * Sets the Y position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). * @param {Number} The Y position of the element * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object * @return {Ext.Element} this */ setY : function(y, animate){ if(!animate || !A){ D.setY(this.dom, y); }else{ this.setXY([this.getX(), y], this.preanim(arguments, 1)); } return this; }, /** * Sets the element's left position directly using CSS style (instead of {@link #setX}). * @param {String} left The left CSS property value * @return {Ext.Element} this */ setLeft : function(left){ this.setStyle("left", this.addUnits(left)); return this; }, /** * Sets the element's top position directly using CSS style (instead of {@link #setY}). * @param {String} top The top CSS property value * @return {Ext.Element} this */ setTop : function(top){ this.setStyle("top", this.addUnits(top)); return this; }, /** * Sets the element's CSS right style. * @param {String} right The right CSS property value * @return {Ext.Element} this */ setRight : function(right){ this.setStyle("right", this.addUnits(right)); return this; }, /** * Sets the element's CSS bottom style. * @param {String} bottom The bottom CSS property value * @return {Ext.Element} this */ setBottom : function(bottom){ this.setStyle("bottom", this.addUnits(bottom)); return this; }, /** * Sets the position of the element in page coordinates, regardless of how the element is positioned. * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). * @param {Array} pos Contains X & Y [x, y] values for new position (coordinates are page-based) * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object * @return {Ext.Element} this */ setXY : function(pos, animate){ if(!animate || !A){ D.setXY(this.dom, pos); }else{ this.anim({points: {to: pos}}, this.preanim(arguments, 1), 'motion'); } return this; }, /** * Sets the position of the element in page coordinates, regardless of how the element is positioned. * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). * @param {Number} x X value for new position (coordinates are page-based) * @param {Number} y Y value for new position (coordinates are page-based) * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object * @return {Ext.Element} this */ setLocation : function(x, y, animate){ this.setXY([x, y], this.preanim(arguments, 2)); return this; }, /** * Sets the position of the element in page coordinates, regardless of how the element is positioned. * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false). * @param {Number} x X value for new position (coordinates are page-based) * @param {Number} y Y value for new position (coordinates are page-based) * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object * @return {Ext.Element} this */ moveTo : function(x, y, animate){ this.setXY([x, y], this.preanim(arguments, 2)); return this; }, /** * Returns the region of the given element. * The element must be part of the DOM tree to have a region (display:none or elements not appended return false). * @return {Region} A Ext.lib.Region containing "top, left, bottom, right" member data. */ getRegion : function(){ return D.getRegion(this.dom); }, /** * Returns the offset height of the element * @param {Boolean} contentHeight (optional) true to get the height minus borders and padding * @return {Number} The element's height */ getHeight : function(contentHeight){ var h = this.dom.offsetHeight || 0; h = contentHeight !== true ? h : h-this.getBorderWidth("tb")-this.getPadding("tb"); return h < 0 ? 0 : h; }, /** * Returns the offset width of the element * @param {Boolean} contentWidth (optional) true to get the width minus borders and padding * @return {Number} The element's width */ getWidth : function(contentWidth){ var w = this.dom.offsetWidth || 0; w = contentWidth !== true ? w : w-this.getBorderWidth("lr")-this.getPadding("lr"); return w < 0 ? 0 : w; }, /** * Returns either the offsetHeight or the height of this element based on CSS height adjusted by padding or borders * when needed to simulate offsetHeight when offsets aren't available. This may not work on display:none elements * if a height has not been set using CSS. * @return {Number} */ getComputedHeight : function(){ var h = Math.max(this.dom.offsetHeight, this.dom.clientHeight); if(!h){ h = parseInt(this.getStyle('height'), 10) || 0; if(!this.isBorderBox()){ h += this.getFrameWidth('tb'); } } return h; }, /** * Returns either the offsetWidth or the width of this element based on CSS width adjusted by padding or borders * when needed to simulate offsetWidth when offsets aren't available. This may not work on display:none elements * if a width has not been set using CSS. * @return {Number} */ getComputedWidth : function(){ var w = Math.max(this.dom.offsetWidth, this.dom.clientWidth); if(!w){ w = parseInt(this.getStyle('width'), 10) || 0; if(!this.isBorderBox()){ w += this.getFrameWidth('lr'); } } return w; }, /** * Returns the size of the element. * @param {Boolean} contentSize (optional) true to get the width/size minus borders and padding * @return {Object} An object containing the element's size {width: (element width), height: (element height)} */ getSize : function(contentSize){ return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)}; }, getStyleSize : function(){ var w, h, d = this.dom, s = d.style; if(s.width && s.width != 'auto'){ w = parseInt(s.width, 10); if(Ext.isBorderBox){ w -= this.getFrameWidth('lr'); } } if(s.height && s.height != 'auto'){ h = parseInt(s.height, 10); if(Ext.isBorderBox){ h -= this.getFrameWidth('tb'); } } return {width: w || this.getWidth(true), height: h || this.getHeight(true)}; }, /** * Returns the width and height of the viewport. * @return {Object} An object containing the viewport's size {width: (viewport width), height: (viewport height)} */ getViewSize : function(){ var d = this.dom, doc = document, aw = 0, ah = 0; if(d == doc || d == doc.body){ return {width : D.getViewWidth(), height: D.getViewHeight()}; }else{ return { width : d.clientWidth, height: d.clientHeight }; } }, /** * Returns the value of the "value" attribute * @param {Boolean} asNumber true to parse the value as a number * @return {String/Number} */ getValue : function(asNumber){ return asNumber ? parseInt(this.dom.value, 10) : this.dom.value; }, // private adjustWidth : function(width){ if(typeof width == "number"){ if(this.autoBoxAdjust && !this.isBorderBox()){ width -= (this.getBorderWidth("lr") + this.getPadding("lr")); } if(width < 0){ width = 0; } } return width; }, // private adjustHeight : function(height){ if(typeof height == "number"){ if(this.autoBoxAdjust && !this.isBorderBox()){ height -= (this.getBorderWidth("tb") + this.getPadding("tb")); } if(height < 0){ height = 0; } } return height; }, /** * Set the width of the element * @param {Number} width The new width * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object * @return {Ext.Element} this */ setWidth : function(width, animate){ width = this.adjustWidth(width); if(!animate || !A){ this.dom.style.width = this.addUnits(width); }else{ this.anim({width: {to: width}}, this.preanim(arguments, 1)); } return this; }, /** * Set the height of the element * @param {Number} height The new height * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -