Javascript getPosition


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function findPosition(obj) {
  2.  
  3. var curleft = curtop = 0;
  4.  
  5. if (obj.offsetParent) {
  6. do {
  7. curleft += obj.offsetLeft;
  8. curtop += obj.offsetTop;
  9. } while (obj = obj.offsetParent);
  10. }
  11.  
  12. var arrPositions = new Array();
  13. arrPositions[0] = curleft; // LEFT
  14. arrPositions[1] = curtop; // TOP
  15.  
  16. return arrPositions;
  17. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.