SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Detecting Table Position (Y Coords)

    Ok,

    What I need to do is simply find the y coordinates of a specific table when I click on that specific table.

    Any help would be greatly appreciated,

    Judd

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2005
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As far as I know, the table should be positioned using CSS, like this:

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    <
    HTML
    <
    HEAD
    <
    META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"
    <
    TITLE>Untitled Page</TITLE

    <
    SCRIPT TYPE="text/javascript"

            function 
    Pos() { 

                     var 
    Top  document.getElementById("MyTable").style.top
                     var 
    Left document.getElementById("MyTable").style.left

                     
    alert("The Table is in position: Top=" Top ", Left=" Left); 

            } 

    </SCRIPT> 


    </HEAD> 

    <BODY bgcolor="#FFFFFF" text="#000000"> 

    <DIV ID="MyTable" onclick="Pos()" style="position:absolute;left:100px;top:25px;width:179px;height:147px;z-index:1" 

    align="left">
    <TABLE width="100%" height="100%" border="1" cellpadding="0" cellspacing="1">
    <TR>
    <TD align="left" valign="top" width="86" height="70">&nbsp;</TD>
    <TD align="left" valign="top" width="88" height="70">&nbsp;</TD>
    </TR>
    <TR>
    <TD align="left" valign="top" width="86" height="72">&nbsp;</TD>
    <TD align="left" valign="top" width="88" height="72">&nbsp;</TD>
    </TR>
    </TABLE></DIV>

    </BODY> 
    </HTML> 

  3. #3
    SitePoint Addict MadDog's Avatar
    Join Date
    Aug 2002
    Location
    Oregon, USA
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is some code i use to find the X and Y coordinate of an object:

    Code:
    //function to find the X coordinate of an object
     function findPosX(obj) {
     	var curleft = 0;
     	if(obj.offsetParent)
     		while(1)
     		{
     		  curleft += obj.offsetLeft;
     		  if(!obj.offsetParent)
     			break;
     		  obj = obj.offsetParent;
     		}
     	else if(obj.x)
     		curleft += obj.x;
     	return curleft;
       }
     
     //function to find the Y coordinate of an object
     function findPosY(obj)
       {
     	var curtop = 0;
     	if(obj.offsetParent)
     		while(1)
     		{
     		  curtop += obj.offsetTop;
     		  if(!obj.offsetParent)
     			break;
     		  obj = obj.offsetParent;
     		}
     	else if(obj.y)
     		curtop += obj.y;
     	return curtop;
       }
    call it like this:
    Code:
    tableX = findPosX(document.getElementById('tableIDHere'));
    Drew Gauderman
    ASP/MSSQL/AJAX-Javascript/HTML/CSS Coder
    iPortalX The most secure FREE ASP portal!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •