Coordinates of divs and tables without absolute positioning?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Siegfried Heintze

    Coordinates of divs and tables without absolute positioning?

    I want to implement drag and drop for tables, divs, spans. The problem is
    that I don't know how wide or long my tables, divs and spans are going to be
    in advance so I cannot use absolute coordinates. (It always seemed odd to me
    that there is no function called GetExtent that would return the bounding
    rectangle of an object -- this would solve my problem).

    There is a way, however, to fetch the coordinates of an object (such as a
    table, or td, or span) and then change the positioning to absolute and then
    change the coordinates according to the mouse movements.

    How do I get the coordinates? I tried doing
    alert(document. getElementById( 'x').style.left ) but this only returned an
    empty string.

    I know it is possible because I posted this query once before (about a year
    ago) and received a response but cannot remember where I saved it!

    Thanks,
    Siegfried


  • pcx99

    #2
    Re: Coordinates of divs and tables without absolute positioning?

    Siegfried Heintze wrote:
    [color=blue]
    > I want to implement drag and drop for tables, divs, spans. The problem is
    > that I don't know how wide or long my tables, divs and spans are going to be
    > in advance so I cannot use absolute coordinates. (It always seemed odd to me
    > that there is no function called GetExtent that would return the bounding
    > rectangle of an object -- this would solve my problem).
    >
    > There is a way, however, to fetch the coordinates of an object (such as a
    > table, or td, or span) and then change the positioning to absolute and then
    > change the coordinates according to the mouse movements.
    >
    > How do I get the coordinates? I tried doing
    > alert(document. getElementById( 'x').style.left ) but this only returned an
    > empty string.
    >
    > I know it is possible because I posted this query once before (about a year
    > ago) and received a response but cannot remember where I saved it!
    >
    > Thanks,
    > Siegfried
    >
    >[/color]


    Use DHTML. In the table or div tag add onMouseOver and onMouseOut
    events to set a variable indicating which element the mouse is over.

    IE <table onMouseOver="ac tiveElement=1" onMouseOut="act iveElement=0">

    If you need precise coordinates, you can give the html element a name
    tag then...

    nameid=document .getElementById ("name");
    y=nameid.style. top;
    x=nameid.style. left;

    Comment

    Working...