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, directly return the replaced value
if (propertyCache[property]) {
return propertyCache[property];
}
// Use regular expression to replace
var = property;
converted while( patterns.HYPHEN.exec(converted) ) {
converted = converted.replace(RegExp.$1,
RegExp.$1.substr(1).toUpperCase());
}
// Store in cache
propertyCache[property] = converted;
return converted;
}; In YAHOO.util.Dom, the getStyle function considers more differences For browser compatibility issues, the code is as follows
// Use W3C DOM standard browsers, such as Firefox, Opera, Safari
if (document.defaultView && document.defaultView.getComputedStyle) {
getStyle = function(el, property) {
var value = null;
// Rename part of the CSS style name
if (property == 'float') {
property = 'cssFloat'; 🎜> value = . >} else if (document.documentElement.currentStyle && isIE) {
getStyle = function(el, property) { // "Convert" name to IE to be recognized
case 'opacity' :
var val = 100;
try {
val =
el.filters['DXImageTransform.Microsoft.Alpha'].opacity; (e) {
try {
val = el.filters('alpha').opacity;
} catch(e) {
el.currentStyle[property] : null;
🎜> getStyle = function(el, property) { return el.style[property]; };
} In addition, PPK’s explanation of getStyle on his blog is also very exciting. If you are interested, you can read it .