JSページ要素座標を取得します.
1088 ワード
javascript元素の幅、高さ、座標の設定:
Dcument.getElemenntById.style.width=value Dcument.getElemenntById.style.height=value Dcument.getElemenntById.style.top=value Dcument.getElementById.style.left=value
取得:
value=document.getElemenntById.offsetLeft value=document.getElemenntById.offsetTop value=document.getElemenntById.offsetWidth value=document.getElemenntById.offsetHeight
元素の座標を探します.
Dcument.getElemenntById.style.width=value Dcument.getElemenntById.style.height=value Dcument.getElemenntById.style.top=value Dcument.getElementById.style.left=value
取得:
value=document.getElemenntById.offsetLeft value=document.getElemenntById.offsetTop value=document.getElemenntById.offsetWidth value=document.getElemenntById.offsetHeight
元素の座標を探します.
function findPosition( oElement )
{
var x2 = 0;
var y2 = 0;
var width = oElement.offsetWidth;
var height = oElement.offsetHeight;
alert(width + "=" + height);
if( typeof( oElement.offsetParent ) != 'undefined' )
{
for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent )
{
posX += oElement.offsetLeft;
posY += oElement.offsetTop;
}
x2 = posX + width;
y2 = posY + height;
return [ posX, posY ,x2, y2];
} else{
x2 = oElement.x + width;
y2 = oElement.y + height;
return [ oElement.x, oElement.y, x2, y2];
}
}