指定したレイヤーの座標を取得

9月 16, 2006 · Posted in javascript 

概要

指定したレイヤーの座標を取得します。

Java Script
function getElementPosition(eremID){
var offsetTrail = document.getElementById(eremID);
var offsetLeft = 0;
var offsetTop = 0;
while(offsetTrail){
offsetLeft += offsetTrail.offsetLeft;
offsetTop += offsetTrail.offsetTop;
offsetTrail = offsetTrail.offsetParent;
}
if(navigator.userAgent.indexOf("Mac") != -1 &&
typeof document.body.leftMargin != "undefined"){
offsetLeft += document.body.leftMargin;
offsetTop += document.body.topMargin;
}
return{ left:offsetLeft , top:offsetTop }
}

Comments

Comments are closed.