获取绝对距离

function getPos(obj){
    var l = 0;
    var t = 0;
    while (obj){
        l += obj.offsetLeft;
        t += obj.offsetTop;
        obj = obj.offsetParent;
    }   
    return {top: t, left: l};
    
}

你可能感兴趣的:(获取绝对距离)