Top left coner of html control

S

Shimon Sim

Is it possible to find top left corner of a control using JavaScript?
As far as I know it is very easy to do if you use Grid layout while
designing a page. But if you are using flow layout I didn't find any method
to find top left corner of a control.

I see drop down calendars that drop right under control even though I
designed page in flow layout.
How do they do it?
Thank,
Shimon.
 
S

Steven Cheng[MSFT]

Thanks for Steve's informative inputs

Hi Shimon,

For html elements in non-absolute layout html page, we need to use
recursive script function to get their absolute postion on the whole page.
For example:


function getAbsoluteLeft(oNode)
{
var oCurrentNode = oNode;
var iLeft = 0;
while(oNode != null && oCurrentNode.tagName != "BODY" )
{
iLeft += oCurrentNode.offsetLeft;
oCurrentNode=oCurrentNode.offsetParent;
}

return iLeft;
}

function getAbsoluteTop(oNode)
{
var oCurrentNode = oNode;
var iTop = 0;
while(oNode != null && oCurrentNode.tagName != "BODY")
{
iTop += oCurrentNode.offsetTop;
oCurrentNode = oCurrentNode.offsetParent;
}
return iTop; }

However, such scripts also depend on the browser's script model support,
I've test the above functions on IE6 and it works. Hope also helps.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top