Publi

Conocer la posición de un objeto (Javascript)

Posteo un par de funciones para saber la posición absoluta (x,y) de un objeto en Javascript:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function getX( oElement )
{
  var iReturnValue = 0;
  while( oElement != null ) {
    iReturnValue += oElement.offsetLeft;
    oElement = oElement.offsetParent;
  }
  return iReturnValue;
}

function getY( oElement )
{
  var iReturnValue = 0;
  while( oElement != null ) {
    iReturnValue += oElement.offsetTop;
    oElement = oElement.offsetParent;
  }
  return iReturnValue;
}

Encontré la función getY en este foro.

Con estas funciones podremos saber la posición de los objetos con respecto a la ventana del navegador.

También podría interesarte....

There are 5 comments left Ir a comentario

  1. Matias /
    Usando Google Chrome Google Chrome 29.0.1600.1 en Windows Windows 7

    Gracias, funciona perfecto.

  2. Mike Rooney /
    Usando Google Chrome Google Chrome 109.0.0.0 en Windows Windows NT

    I found your this post while searching for some related information on blog search…Its a good post.Rio Julio Pena Blazer

  3. Andrew Mark /
    Usando Google Chrome Google Chrome 109.0.0.0 en Windows Windows NT

    Your post content is being interested by a lot of people, I am very impressed with your post. I hope to receive more good articles.
    Yellowstone Season 5 Ryan Jacket

  4. fdgvsd /
    Usando Google Chrome Google Chrome 112.0.0.0 en Windows Windows NT

    Great information, I will recommend it to my friends for them to check out. Thanks for sharing! If you have more time, please visit: trap the cat

  5. Theodore Evans /
    Usando Google Chrome Google Chrome 113.0.0.0 en Windows Windows NT

    That article is well written. Don’t stop making changes to your blog five nights at freddy’s

Leave a Reply