原生JS代码封装(获取位置)
作者:互联网
function getPagePos(ele){
if(!ele) throw new Error("ele参数有问题,无法获取位置");
var _left = ele.offsetLeft;
var _top = ele.offsetTop;
while(ele.offsetParent) {
_left += ele.offsetParent.offsetLeft;
_top += ele.offsetParent.offsetTop;
ele = ele.offsetParent;
}
return {
x : _left,
y : _top
};
}
标签:原生,封装,offsetParent,top,ele,offsetTop,var,JS,left 来源: https://www.cnblogs.com/sunyang-001/p/10812894.html