프론트앤드 개발

높이에 따라서 세로중앙정렬되게 하는스크립트

긴자손 2011. 5. 4. 17:26
728x90
반응형

window.onload = onLoadHandler;

window.onresize = resizeSwfDiv;

var isFull = false;

function onLoadHandler()

{

resizeSwfDiv();

}

function isFullSetting( _isFull )

{

isFull = Boolean(_isFull);

}

function resizeSwfDiv()

{

var _div = document.getElementById("flashWrap");

if(navigator.userAgent.indexOf('MSIE')!=-1){

var _bh = document.body.clientHeight;

if(_bh < 768){

_bh = 0;

_div.style.margin = _bh+' auto 0px auto';

}

else{

_bh = (_bh - 768)/2 + "px";

_div.style.margin = _bh+' auto 0px auto';

}

}

else{

var _bh = innerHeight;

if(_bh < 768){

_bh = 0;

_div.style.margin = _bh+' auto 0px auto';

}

else{

_bh = (_bh - 768)/2 + "px";

_div.style.margin = _bh+' auto 0px auto';

}

}

</script>


브라우저를 줄이거나 늘려도 항상 가운데 있게 된다...


세로정렬


가로는 css를 이용해서


margin:0px auto;를 사용하면된다.


728x90
반응형