...

View Full Version : finding an image's top position?



tyler jones
07-01-2003, 04:30 PM
How can I figure out where the top of an image is on a page? I've tried imageTop = document.getElementById('add').style.top; but it's not giving me anything. It's alerting, but just an empty value. So, I'm not sure what I'm doing wrong. Thanks.

A1ien51
07-01-2003, 04:41 PM
If you do not have the image defined, then that is not going to work

You would have to use a code like this:



ErrorGapX=0;
ErrorGapY=0;

function ErrorPosition(ErrorElement){
ErrorPosX = ErrorElement.offsetLeft
ErrorPosY = ErrorElement.offsetTop;
ErrorWidth = ErrorElement.clientWidth;
TheElement = ErrorElement.offsetParent;
while(TheElement != null){
ErrorPosX += TheElement.offsetLeft
ErrorPosY += TheElement.offsetTop;
TheElement = TheElement.offsetParent;
}
ErrorPosX += ErrorGapX;
ErrorPosY += ErrorGapY;
return ErrorPosX + "|" + ErrorPosY;
}


//Use this to find the position by setting variable TheObj
Spot=ErrorPosition(TheObj);
Spot=Spot.split("|");
Cx=Spot[0]*1;
Cy=Spot[1]*1;

cheesebagpipe
07-01-2003, 08:09 PM
http://www.webreference.com/dhtml/diner/realpos1/index.html



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum