function getoffset(e) {
var t = e.offsetTop;
var l = e.offsetLeft;
while (e = e.offsetParent) {
t += e.offsetTop;
l += e.offsetLeft;
}
var result = {};
result.offsetTop = t;
result.offsetLeft = l;
return result;
}
转载于:https://www.cnblogs.com/yuanxiaoping_21cn_com/archive/2013/04/28/3049529.html