Exact top left coordinates of movable image.

Discussion in 'Javascript' started by MarkusJNZ@gmail.com, Oct 23, 2006.

  1. Guest

    Hi all, I have a page which allows a user to drag and drop one or more
    images on a page.

    I have a function which is passed in a reference to the item being
    dragged so I can do things like;

    Pseudo code below:

    function Drop(obj)
    {
    alert(document.GetByElementId(obj).style.posLeft);
    }

    The above seems to give the offset x coordinate from the objects
    original position.

    Likewise I have tried

    alert(document.GetByElementId(obj).style.Left); Which gives the same
    value

    I have also tried capturing the x and y coordinate of the mouse when
    the person releases the mouse button. The problem is that if the person
    drags the image in the middle then it does not give the correct top
    left of the image.

    So, can anyone please tell me how I can get the top left coordinates of
    the item being dragged when a person releases the mouse button?

    TIA
    Markus
    ==================================
    googlenews2006markusj
    , Oct 23, 2006
    #1
    1. Advertising

  2. RobG Guest

    RobG, Oct 23, 2006
    #2
    1. Advertising

  3. RobG wrote:
    > wrote:
    > > Hi all, I have a page which allows a user to drag and drop one or more
    > > images on a page.

    >
    > [...]
    >
    > > So, can anyone please tell me how I can get the top left coordinates of
    > > the item being dragged when a person releases the mouse button?

    >
    > Peter-Paul Koch gives some explaination of position here:
    > <URL: http://www.quirksmode.org/js/findpos.html >
    >
    >
    > Try Matt Kruse's Position library:
    > <URL: http://www.javascripttoolbox.com/lib/objectposition/ >


    I did find that these positioning algorithms didn't work properly in
    IE, Firefox, Opera and Safari on Mac and Windows. They all had one
    problem in at least one browser. The test cases included nested
    scrolling elements and tables.

    I have found that with dragdrop you can usually find ways to avoid
    needing the position calculated in the complex offsetParent way. Just
    inline style coordinates relative to the first ancestor with
    position:relative or other simple ways. With all the browser
    difficulties in element positioning I have been trying to avoid it when
    possible and that has seemed like all the time lately.

    Peter
    Peter Michaux, Oct 24, 2006
    #3
  4. Guest

    Thanks everyone!
    Regards
    Markus
    Peter Michaux wrote:
    > RobG wrote:
    > > wrote:
    > > > Hi all, I have a page which allows a user to drag and drop one or more
    > > > images on a page.

    > >
    > > [...]
    > >
    > > > So, can anyone please tell me how I can get the top left coordinates of
    > > > the item being dragged when a person releases the mouse button?

    > >
    > > Peter-Paul Koch gives some explaination of position here:
    > > <URL: http://www.quirksmode.org/js/findpos.html >
    > >
    > >
    > > Try Matt Kruse's Position library:
    > > <URL: http://www.javascripttoolbox.com/lib/objectposition/ >

    >
    > I did find that these positioning algorithms didn't work properly in
    > IE, Firefox, Opera and Safari on Mac and Windows. They all had one
    > problem in at least one browser. The test cases included nested
    > scrolling elements and tables.
    >
    > I have found that with dragdrop you can usually find ways to avoid
    > needing the position calculated in the complex offsetParent way. Just
    > inline style coordinates relative to the first ancestor with
    > position:relative or other simple ways. With all the browser
    > difficulties in element positioning I have been trying to avoid it when
    > possible and that has seemed like all the time lately.
    >
    > Peter
    , Oct 25, 2006
    #4
    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. Joe Butler
    Replies:
    15
    Views:
    9,431
    Barefoot Kid
    Oct 22, 2003
  2. Suresh  Kumar
    Replies:
    0
    Views:
    580
    Suresh Kumar
    Jul 3, 2003
  3. Suresh  Kumar
    Replies:
    0
    Views:
    507
    Suresh Kumar
    Jul 4, 2003
  4. JimFurrow
    Replies:
    1
    Views:
    89
  5. Replies:
    1
    Views:
    123
Loading...

Share This Page