Yahoo. util. Dom-part.3

Source: Internet
Author: User

VaR patterns = {
Hyphen:/(-[A-Z])/I,
Root_tag:/^ body | HTML $/I
};

VaR tocamel = function (property ){
// If no-[A-Z] letter exists, return directly
If (! Patterns. hyphen. Test (property )){
Return property;
}

// If there is a cache, the replaced value is directly returned.
If (propertycache [property]) {
Return propertycache [property];
}

// Use regular expression replacement
VaR converted = property;
While (patterns.hyphen.exe C (converted )){
Converted = converted. Replace (Regexp. $1,
Regexp. $1. substr (1). touppercase ());
}

// Save to cache
Propertycache [property] = converted;
Return converted;
}; In Yahoo. util. Dom, The getstyle function considers more compatibility issues with different browsers,CodeAs follows:

// Use W3C Dom standard browsers, such as Firefox, opera, and Safari
If (document. defaultview & document. defaultview. getcomputedstyle ){
Getstyle = function (El, property ){
VaR value = NULL;

// Rename some CSS style names
If (property = 'float '){
Property = 'cssfloat ';
}

// Obtain the attributes added with CSS.
VaR computed = Document. defaultview. getcomputedstyle (El ,'');
If (computed ){
Value = computed [tocamel (property)];
}

return el. style [property] | value;
};
// if it is an IE browser
} else if (document.doc umentelement. currentstyle & isie) {
getstyle = function (El, property) {
switch (tocamel (property )) {
// the name of "Conversion" is something that IE can recognize
case 'opacity ':
var val = 100;
try {
val =
el. filters ['dximagetransform. microsoft. alpha ']. opacity;
}catch (e) {
try {
val = el. fi Lters ('alpha '). opacity;
}catch (e) {
}< BR >}< br> // percentage
return Val/100;
case 'float':
property = 'stylefloat';
default:
VaR value = el. currentstyle? El. currentstyle [property]: NULL;
return (El. style [property] | value);
}< BR> };
} else {
// obtain the inline style
getstyle = function (El, property) {return el. style [property] ;};< BR >}in addition, PPK's elaborate on getstyle on his blog is also wonderful. If you are interested, you can check it out.

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.