Js获取元素在页面里的坐标位置和宽高

 1 //获取元素在页面里的位置和宽高
 2 function getPosition(obj) {
 3     var top = 0,
 4         left = 0,
 5         width = obj.offsetWidth,
 6         height = obj.offsetHeight;
 7 
 8     while(obj.offsetParent){
 9         top += obj.offsetTop;
10         left += obj.offsetLeft;
11         obj = obj.offsetParent;
12     }
13 
14     return {"top":top,"left":left,"width":width,"height":height};
15 }

 

 

posted @ 2012-07-05 09:56  dtdxrk  阅读(1139)  评论(0编辑  收藏  举报