Get DOM Element Page Offset - Node.js DOM

Node.js examples for DOM:Element

Description

Get DOM Element Page Offset

Demo Code


function getDOMElementPageOffset ( elem )
{
  var x = 0;/*www .jav a 2  s .  co m*/
  var y = 0;

  for ( ; elem; elem = elem.offsetParent )
  {
//    x += elem.offsetLeft - elem.scrollLeft;
//    y += elem.offsetTop - elem.scrollTop;

    x += elem.offsetLeft;
    y += elem.offsetTop;

  }

  return vec( x, y );
}

Related Tutorials