프로그램/html

객체 절대 좌표 구하기

milktea.kang 2010. 12. 14. 12:18
객체 절대 좌표 구하기

function getAbsolutePos(obj) {
var position = new Object;
position.x = 0;
position.y = 0;
if( obj ) {
position.x = obj.offsetLeft + obj.clientLeft;
position.y = obj.offsetTop + obj.clientTop;
if( obj.offsetParent ) {
var parentpos = getAbsolutePos(obj.offsetParent);
position.x += parentpos.x;
position.y += parentpos.y;
}
}
return position;
}