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. Top Gun Leather Jacket UK /
    Usando Google Chrome Google Chrome 116.0.0.0 en Windows Windows NT

    Excellent article. The writing style which you have used in this article is very good and it made the article of better quality.

  3. Kendall /
    Usando Google Chrome Google Chrome 120.0.0.0 en Windows Windows NT

    A masterful job of distilling complex subway surfers unblocked ideas into a concise and understandable format.

  4. Usando Google Chrome Google Chrome 121.0.0.0 en Windows Windows NT

    Thanks for sharing informative post. It is one of the best site that I have visited. Hope you will share more quality blog posts thank you.

  5. liza memozi /
    Usando Google Chrome Google Chrome 121.0.0.0 en Windows Windows NT

    There is a lot of useful and detailed information in your article. You can relax by going to poppy playtime page.

Leave a Reply