Posted By

huacnlee on 05/15/08


Tagged

javascript size posation


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

ki4ngel


getPos


 / Published in: JavaScript
 

URL: http://huacn.blogbus.com

取得对向的大小和坐标 兼容多种浏览器

  1. /**
  2.  * 取得对向的大小和坐标 兼容多种浏览器
  3.  * @param {Object} owner
  4.  */
  5. var getPos = function(owner){
  6. if(owner == undefined){
  7. return {top : 0, left:0 , width : 0, height : 0};
  8. }
  9.  
  10. var e = owner;
  11. var oTop = e.offsetTop;
  12. var oLeft = e.offsetLeft;
  13. var oWidth = e.offsetWidth;
  14. var oHeight = e.offsetHeight;
  15. while(e = e.offsetParent)
  16. {
  17. oTop += e.offsetTop;
  18. oLeft += e.offsetLeft;
  19. }
  20.  
  21. return {
  22. top : oTop,
  23. left : oLeft,
  24. width : oWidth,
  25. height : oHeight
  26. }
  27. }

Report this snippet  

You need to login to post a comment.