Poesía Binaria

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....