iframe relative mouse position

Discussion in 'Javascript' started by madmike, Jul 16, 2003.

  1. madmike

    madmike Guest

    Hi,


    I have an iframe with some javascipt that gets the mouse x and y
    position like this:
    //inside the iframe's onmousemove call back funciton
    xMousePos = window.event.clientX + document.body.scrollLeft;
    yMousePos = window.event.clientY + document.body.scrollTop;

    This gets the x and y position inside the iframe. But what I want is
    the x and y position of the parent window, not the screen like
    screenX. Is there any easy way to get parentX and parentY or to get
    the offset x and y of the iframe relitive to the parent from inside
    the iframe?


    thanks in advance,
    mike
     
    madmike, Jul 16, 2003
    #1
    1. Advertising

  2. madmike

    Csaba2000 Guest

    The way I've done this in the past (if memory serves) is to find the element containing the IFrame and then percolate
    up using .offsetParent

    Csaba Gabor

    "madmike" <> wrote in message news:...
    > Hi,
    >
    >
    > I have an iframe with some javascipt that gets the mouse x and y
    > position like this:
    > //inside the iframe's onmousemove call back funciton
    > xMousePos = window.event.clientX + document.body.scrollLeft;
    > yMousePos = window.event.clientY + document.body.scrollTop;
    >
    > This gets the x and y position inside the iframe. But what I want is
    > the x and y position of the parent window, not the screen like
    > screenX. Is there any easy way to get parentX and parentY or to get
    > the offset x and y of the iframe relitive to the parent from inside
    > the iframe?
    >
    >
    > thanks in advance,
    > mike
     
    Csaba2000, Jul 16, 2003
    #2
    1. Advertising

  3. madmike

    madmike Guest

    this worked for me.

    // get the position relitive to the entire window
    var el =parent.frames[FRAME_NAME].frameElement.offsetParent;
    var x = 0, y = 0;

    while (el)
    {
    x += el.offsetLeft;
    y += el.offsetTop;
    el = el.offsetParent;
    }
     
    madmike, Jul 17, 2003
    #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. Max
    Replies:
    7
    Views:
    9,154
  2. MAB
    Replies:
    31
    Views:
    26,974
    chrisbster
    May 13, 2009
  3. tom arnall
    Replies:
    6
    Views:
    1,292
    Ian Shef
    Jan 18, 2007
  4. Amir Kouchekinia

    Zoom relative to mouse position

    Amir Kouchekinia, May 20, 2008, in forum: Java
    Replies:
    6
    Views:
    1,812
    John B. Matthews
    May 23, 2008
  5. Nikolai Prokoschenko

    Mouse position in both fixed and relative positioning

    Nikolai Prokoschenko, May 17, 2011, in forum: Javascript
    Replies:
    2
    Views:
    1,086
    darwinist
    May 18, 2011
Loading...

Share This Page