Coordinates of divs and tables without absolute positioning?

Discussion in 'Javascript' started by Siegfried Heintze, Apr 6, 2004.

  1. 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
     
    Siegfried Heintze, Apr 6, 2004
    #1
    1. Advertising

  2. Siegfried Heintze

    pcx99 Guest

    Siegfried Heintze wrote:

    > 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
    >
    >



    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="activeElement=1" onMouseOut="activeElement=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;
     
    pcx99, May 1, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rich
    Replies:
    0
    Views:
    734
  2. Suresh  Kumar
    Replies:
    0
    Views:
    601
    Suresh Kumar
    Jul 3, 2003
  3. Suresh  Kumar
    Replies:
    0
    Views:
    521
    Suresh Kumar
    Jul 4, 2003
  4. Replies:
    6
    Views:
    114
  5. maya
    Replies:
    4
    Views:
    250
Loading...

Share This Page