function offset(element) {
var pos = { left: 0, top: 0 }
var parents = element.offsetParent
pos.left += element.offsetLeft
pos.top += element.offsetTop
while (parents && !/html|body/i.test(parents.tagName)) {
pos.left += parents.offsetLeft
pos.top += parents.offsetTop
parents = parents.offsetParent
}
return pos
}
网友评论