topical media & game development

talk show tell print

#javascript-code-04-page.js / js



  // Find the X (Horizontal, Left) position of an element
  function pageX(elem) {
      var p = 0;
  
      // We need to add up all of the offsets for every parent
      while ( elem.offsetParent ) {
          // Add the offset to the current count
          p += elem.offsetLeft;
  
          // and continue on to the next parent
          elem = elem.offsetParent;
      }
  
      return p;
  }
  
  // Find the Y (Vertical, Top) position of an element
  function pageY(elem) {
      var p = 0;
  
      // We need to add up all the offsets for every parent
      while ( elem.offsetParent ) {
          // Add the offset to the current count
          p += elem.offsetTop;
  
          // and continue on to the next parent
          elem = elem.offsetParent;
      }
  
      return p;
  }
  
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.