forked from WangJia-mm/JavaScript201708
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathranjunjun.js
More file actions
26 lines (24 loc) · 837 Bytes
/
ranjunjun.js
File metadata and controls
26 lines (24 loc) · 837 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
function getCss(curEle, attr) {
var val, opaReg;
if ('getComputedStyle' in window) {
val = window.getComputedStyle(curEle, null)[attr];
} else {
if (attr.toLowerCase() === "opacity") {
val = curEle.currentStyle["filter"];
opaReg = /\d+(\.\d+)?/;
val = opaReg.test(val) ? opaReg.exec(val)[0] / 100 : 1;
} else {
val = curEle.currentStyle[attr];
}
}
return isNaN(parseFloat(val)) ? val : parseFloat(val);
}
function setCss(curEle, attr, value) {
if (attr.toLowerCase() === 'opacity') {
curEle.style.opacity = value;
curEle.style.filter = 'alpha(opacity=' + value * 100 + ')';
return;
}
!isNaN(value) && !/^(zIndex|fontWeight)$/i.test(attr) ? value += 'px' : null;
curEle["style"][attr] = value;
}