code: function calculateOffset(element) {
        var style = window.getComputedStyle(element);
        var getCssProperty = function(prop) {
          return parseInt(style.getPropertyValue(prop).replace('px', '')) || 0;
        };
        return {
          left: element.getBoundingClientRect().left + getCssProperty('padding-left'),
          top: element.getBoundingClientRect().top + getCssProperty('padding-top')
        };
      }
docs: Calculates the global offset of the given element more accurately than element.offsetTop and element.offsetLeft.