getBoundingClientRect

getBoundingClientRect_第1张图片
    function getRect(element) {
      var rect = element.getBoundingClientRect();
      var top = document.documentElement.clientTop;
      var left = document.documentElement.clientLeft;
      return {
        top: rect.top - top,
        bottom: rect.bottom - top,
        left: rect.left - left,
        right: rect.right - left
      };
    }

document.documentElement.clientTop; // 非IE为0,IE为2

document.documentElement.clientLeft; // 非IE为0,IE为2

你可能感兴趣的:(getBoundingClientRect)