cursor coordinates relavtive to div

Discussion in 'ASP .Net' started by =?Utf-8?B?cm9kY2hhcg==?=, Oct 17, 2007.

  1. hey all,
    i'm using a mouseover event for my div and i was wondering how to get the
    coordinates of the cursor relative to my DIV. For instance the top left
    corner of my div, no matter where on the screen it is, is 0,0?

    thanks,
    rodchar
    =?Utf-8?B?cm9kY2hhcg==?=, Oct 17, 2007
    #1
    1. Advertising

  2. You need to use JavaScript to find the mouse's coordinates. It's a bit
    of a mess because of the differences between how browsers give you
    cursor coordinates in JavaScript. I would suggest searching something
    like "JavaScript cursor coordinates" in a search engine because there
    are many resources and code examples on the internet, and it would be
    better to find out from there than from me giving you a short example
    that might not work perfectly. One example might not cover all
    browsers or different versions of browsers, and I'm not too clear on
    which browsers use what (for getting mouse coordinates).

    These examples generally will give you coordinates relative to the
    document, not relative to the <div>. You can calculate the location
    relative to the <div> by difference of location of the <div> using
    other JavaScript things. That's also messy because different browsers
    give you the calculated locations of elements in different ways too.

    If you don't get enough information that way and from others who
    reply, you can give it a shot in comp.lang.javascript .

    -Michael Placentra II


    On Oct 17, 4:36 pm, rodchar <> wrote:
    > hey all,
    > i'm using a mouseover event for my div and i was wondering how to get the
    > coordinates of the cursor relative to my DIV. For instance the top left
    > corner of my div, no matter where on the screen it is, is 0,0?
    >
    > thanks,
    > rodchar
    Mike Placentra II, Oct 17, 2007
    #2
    1. Advertising

  3. thank you for the help.
    rod.

    "Mike Placentra II" wrote:

    > You need to use JavaScript to find the mouse's coordinates. It's a bit
    > of a mess because of the differences between how browsers give you
    > cursor coordinates in JavaScript. I would suggest searching something
    > like "JavaScript cursor coordinates" in a search engine because there
    > are many resources and code examples on the internet, and it would be
    > better to find out from there than from me giving you a short example
    > that might not work perfectly. One example might not cover all
    > browsers or different versions of browsers, and I'm not too clear on
    > which browsers use what (for getting mouse coordinates).
    >
    > These examples generally will give you coordinates relative to the
    > document, not relative to the <div>. You can calculate the location
    > relative to the <div> by difference of location of the <div> using
    > other JavaScript things. That's also messy because different browsers
    > give you the calculated locations of elements in different ways too.
    >
    > If you don't get enough information that way and from others who
    > reply, you can give it a shot in comp.lang.javascript .
    >
    > -Michael Placentra II
    >
    >
    > On Oct 17, 4:36 pm, rodchar <> wrote:
    > > hey all,
    > > i'm using a mouseover event for my div and i was wondering how to get the
    > > coordinates of the cursor relative to my DIV. For instance the top left
    > > corner of my div, no matter where on the screen it is, is 0,0?
    > >
    > > thanks,
    > > rodchar

    >
    >
    =?Utf-8?B?cm9kY2hhcg==?=, Oct 26, 2007
    #3
    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. =?Utf-8?B?VG9tYXMgS2VwaWM=?=

    Changing DEFAULT cursor to WAIT cursor in ASP

    =?Utf-8?B?VG9tYXMgS2VwaWM=?=, Apr 5, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    2,287
    Bruce Barker
    Apr 5, 2005
  2. wai-tak sit
    Replies:
    5
    Views:
    14,089
    Thundergo
    Sep 9, 2006
  3. Suresh  Kumar
    Replies:
    0
    Views:
    574
    Suresh Kumar
    Jul 3, 2003
  4. Suresh  Kumar
    Replies:
    0
    Views:
    505
    Suresh Kumar
    Jul 4, 2003
  5. dmaziuk
    Replies:
    3
    Views:
    544
    Chris Gonnerman
    Jan 25, 2011
Loading...

Share This Page