Home > Web Front-end > JS Tutorial > Javascript YUI code reading diary YAHOO.util.Dom - Part.3_YUI.Ext related

Javascript YUI code reading diary YAHOO.util.Dom - Part.3_YUI.Ext related

WBOY
Release: 2016-05-16 19:05:45
Original
974 people have browsed it

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 .

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template