Quantcast
Channel: w3cplus
Viewing all articles
Browse latest Browse all 1557

js设置读取css样式

$
0
0
function css(obj, attr, value){
	switch (arguments.length){
		case 2:
			if(typeof arguments[1] == "object"){
				for (var i in attr) i == "opacity" ? (obj.style["filter"] = "alpha(opacity=" + attr[i] + ")", obj.style[i] = attr[i] / 100) : obj.style[i] = attr[i];
			}else{
				return obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj, null)[attr]
			}
			break;
		case 3:
			attr == "opacity" ? (obj.style["filter"] = "alpha(opacity=" + value + ")", obj.style[attr] = value / 100) : obj.style[attr] = value;
			break;
	}
};

Viewing all articles
Browse latest Browse all 1557

Trending Articles