2018년 1월 31일 수요일

자바스크립트에서 오브젝트의 위치와 사이즈 구하기 (input object etc)


자바스크립트에서 오브젝트의 위치와 사이즈 구하기 (input object etc)

object
input
textarea etc

소스 )
//object의 위치와 사이즈 구하기
function getThisAbsPosition(object){
var position = new Object;
position.x = 0;
position.y = 0;

if( object ) {
position.x = object.offsetLeft;
position.y = object.offsetTop;

if( object.offsetParent ) {
var parentpos = getThisAbsPosition(object.offsetParent);
position.x += parentpos.x;
position.y += parentpos.y;
}
}

position.cx = object.offsetWidth;
position.cy = object.offsetHeight;

return position;
}

이용 )
//new version 위치
var object = document.all.jm_keyword;
var position = getThisAbsPosition(object);
//alert("width : " + position.cx);
//alert("height : " + position.cy);
document.all.ID_POP_JIDO_MENU_WRAP.style.left = (position.x-290)+"px";
document.all.ID_POP_JIDO_MENU_WRAP.style.top = (position.y+10)+"px";


댓글 없음:

댓글 쓰기