-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlayout.js
executable file
·32 lines (26 loc) · 995 Bytes
/
layout.js
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
/** Get the current computed style of an element */
function getStyle(element, strCssRule, returnInt){
if(typeof element==="string"){element=document.getElementById(element);}
var strValue = "";
if(document.defaultView && document.defaultView.getComputedStyle){
strValue = document.defaultView.getComputedStyle(element, "").getPropertyValue(strCssRule);
}
else if(element.currentStyle){
strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){ return p1.toUpperCase(); });
strValue = element.currentStyle[strCssRule];
}
if(returnInt===true){strValue=parseInt(strValue);}
return strValue;
}
function centerDiv(div){
if(typeof div=='string') div=document.getElementById(div);
div.style.position='absolute';
div.style.top='50%';
div.style.left='50%'
div.style.width='';
div.style.heght='';
var width=getStyle(div,'width',true);
var height=getStyle(div,'height',true);
div.style.marginLeft=(width/2)*-1 +'px';
div.style.marginTop=(height/2)*-1 +'px';
}