kiinlam
9/15/2015 - 9:28 AM

获取dom元素尺寸位置信息

获取dom元素尺寸位置信息

function getDomRect(elem) {
    var rect = elem.getBoundingClientRect();
    var top = rect.top;
    var bottom = rect.bottom;
    var left = rect.left;
    var right = rect.right;
    var width = rect.width || right - left;
    var height = rect.height || bottom - top;
    var X = left + (document.documentElement.scrollLeft || document.body.scrollLeft);
    var Y = top + (document.documentElement.scrollTop || document.body.scrollTop);
    return {
        bottom: bottom,
        height: height,
        left: left,
        right: right,
        top: top,
        width: width,
        X: X,
        Y: Y
    };
}