var offset = document.getElementById("btn").getBoundingClientRect();
//在IE6下有2像素的bug
alert(offset.top);
// alert(offset.left);
offsetLeft + offsetTop
alert(getAbsolutePosition(document.getElementById("btn")).top)
//console.log(offset);
function getAbsolutePosition(obj){
var left = 0;
var top = 0;
while(obj){
left += obj.offsetLeft;
top += obj.offsetTop;
obj = obj.offsetParent;
}
return {left:left, top:top};
}
getBoundingClientRect
offsetLeft + offsetTop
https://blog.csdn.net/se134789836178/article/details/103878137