PDA

View Full Version : Position of an image


Sgrdaddy
03-25-2003, 09:49 AM
Hi fellas,

i have a question for you guys:

I have a dynamicly built table with images and i want to know the position of a particular image. The width of al the <TD> isn't the same...


Is theire a way to retrieve the location of such an image?

Weirdan
03-25-2003, 11:06 AM
What for? Describe your goal, may be there are better way to make things work....

Sgrdaddy
03-25-2003, 11:10 AM
i found the solution myself

found this script on www.experts-exchange.com

<HTML><BODY>
<SCRIPT>

function getXYcoord ( nvn ) {
var elm = document.images[nvn];
if ( document.layers ) return elm;

var rd = { x:0 ,y:0 };
do { rd.x += parseInt( elm.offsetLeft );
rd.y += parseInt( elm.offsetTop );
elm = elm.offsetParent;
} while ( elm );
return rd;
}
</SCRIPT>
<img src="IMAGE.GIF" name="imagename">
<SCRIPT>
var pos = getXYcoord( 'imagename' );
alert( "image x,y coords are: " +pos.x +"," +pos.y );
</SCRIPT>