Javascript YUI Read Code Diary of the Yahoo.util.dom-part.3_yui. Ext Related

Source: Internet
Author: User
var patterns = {
Hyphen:/(-[a-z])/I,
Root_tag:/^body|html$/i
};

var Tocamel = function (property) {
If there is no-[a-z] letter, return directly
if (!patterns. Hyphen.test (property)) {
return property;
}

If there is a cache, return the replacement value directly
if (Propertycache[property]) {
return Propertycache[property];
}

Use regular substitution
var converted = property;
while (patterns. Hyphen.exec (converted)) {
converted = Converted.replace (regexp.$1,
REGEXP.$1.SUBSTR (1). toUpperCase ());
}

Cache
Propertycache[property] = converted;
return converted;
In YAHOO.util.Dom, the GetStyle function takes into account a number of different browser compatibility issues, the following code

Browsers using the standard Web-browser, such as Firefox, Opera, Safari
if (Document.defaultview && document.defaultView.getComputedStyle) {
GetStyle = function (El, property) {
var value = null;

Rename a partial CSS style name
if (property = = ' float ') {
property = ' Cssfloat ';
}

Get properties that are added through CSS
var computed = Document.defaultView.getComputedStyle (el, ' ");
if (computed) {
Value = Computed[tocamel (property)];
}

return El.style[property] | | Value
};
If it is IE browser
else if (Document.documentElement.currentStyle && Isie) {
GetStyle = function (El, property) {
Switch (Tocamel (property)) {
The "conversion" name is known to IE
Case ' opacity ':
var val = 100;
try {
val =
el.filters[' DXImageTransform.Microsoft.Alpha '].opacity;
catch (e) {
try {
val = el.filters (' alpha '). Opacity;
catch (e) {
}
}
Percentage
return val/100;
Case ' float ':
property = ' stylefloat ';
Default
var value = El.currentstyle? El.currentstyle[property]: null;
Return (El.style[property] | | value);
}
};
} else {
Get inline style
GetStyle = function (El, property) {return el.style[property];
In addition, PPK on his Blog on the getstyle of the exposition, also very exciting, interested can go to see.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.