var nLayerWidth = 400;               
var nLayerHeight = 200;             

var nLeft = (document.body.scrollLeft + (document.body.clientWidth / 2)) - (nLayerWidth / 2);
var nTop = (document.body.scrollTop + (document.body.clientHeight / 2)) - (nLayerHeight / 2);

var layer = document.createElement('div');                 // div element 생성
layer.style.cssText = "position:absolute;left:" +  nLeft + "px;top:" + nTop + "px;width:" + nLayerWidth + "px;height:" + nLayerHeight  + "px;";                           // css 적용
document.body.appendChild(layer);                          // 생성한 div 표시


tip>
appendChild(layer) 의 반대는?
layer.parentNode.removeChild(layer);           // layer element 제거
반응형

+ Recent posts