element.js
来自「php绿色服务器,让大家试用greenamp」· JavaScript 代码 · 共 1,746 行 · 第 1/5 页
JS
1,746 行
if(typeof el.filter == 'string'){
var fv = parseFloat(el.filter.match(/alpha\(opacity=(.*)\)/i)[1]);
if(!isNaN(fv)){
return fv ? fv / 100 : 0;
}
}
return 1;
}else if(prop == 'float'){
prop = "styleFloat";
}
if(!(camel = propCache[prop])){
camel = propCache[prop] = prop.replace(camelRe, camelFn);
}
if(v = el.style[camel]){
return v;
}
if(cs = el.currentStyle){
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} val (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 eg "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);
},
/**
* 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;
},
/**
* Set the element's left position directly using CSS style (instead of setX())
* @param {String} left The left CSS property value
* @return {Ext.Element} this
*/
setLeft : function(left){
this.setStyle("left", this.addUnits(left));
return this;
},
/**
* Set the element's top position directly using CSS style (instead of setY())
* @param {String} top The top CSS property value
* @return {Ext.Element} this
*/
setTop : function(top){
this.setStyle("top", this.addUnits(top));
return this;
},
/**
* Set 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;
},
/**
* Set 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;
},
/**
* Set 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;
},
/**
* Set 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;
},
/**
* Set 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;
return contentHeight !== true ? h : h-this.getBorderWidth("tb")-this.getPadding("tb");
},
/**
* 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;
return contentWidth !== true ? w : w-this.getBorderWidth("lr")-this.getPadding("lr");
},
/**
* 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)};
},
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
* @return {Ext.Element} this
*/
setHeight : function(height, animate){
height = this.adjustHeight(height);
if(!animate || !A){
this.dom.style.height = this.addUnits(height);
}else{
this.anim({height: {to: height}}, this.preanim(arguments, 1));
}
return this;
},
/**
* Set the size of the element. If animation is true, both width an height will be animated concurrently.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?