-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjspackage.js
More file actions
35 lines (33 loc) · 886 Bytes
/
Copy pathjspackage.js
File metadata and controls
35 lines (33 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
*By starriness in 5/13/2015
**/
function css(obj,attr,val) {
if (obj.nodeType != 1) {return};
var attr = attr.replace(/^\s+|\s+$/g,"");
if (arguments.length==2) {
if (attr == 'opacity') {
return 100*parseInt(obj.currentStyle?(obj.currentStyle[attr]||1):(getComputedStyle(obj,null)[attr]||1))
};
if (attr == 'width' || attr == 'height' || attr == 'top' || attr == 'top') {
var str = 'offset' + attr.replace(attr.charAt(0),attr.charAt(0).toUpperCase());
return obj[str];
};
return obj.currentStyle?obj.currentStyle[attr]:getComputedStyle(obj,null)[attr];
};
if (arguments.length==3) {
switch(attr){
case 'width':
case 'height':
case 'top':
case 'left':
obj.style[attr]=val+'px';
break;
case 'opacity':
obj.style.filter = 'alpha(opacity='+val+')';
obj.style[attr]=val/100;
break;
default:
obj.style[attr]=val;
}
};
}