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 }