function elementPosition(elem, until) {
  let x = 0
  let y = 0
  let inner = true

  while (elem) {
    let style = getComputedStyle(elem, null)
    if(until && until(elem, style)) break
    x += elem.offsetLeft
    y += elem.offsetTop
    y += getNumericStyleProperty(style, 'border-top-width')
    x += getNumericStyleProperty(style, 'border-left-width')
    if (inner) {
      y += getNumericStyleProperty(style, 'padding-top')
      x += getNumericStyleProperty(style, 'padding-left')
    }
    inner = false
    elem = elem.offsetParent
  }
  return {x: x, y: y}
}
Returns the position of an element relative to the page, or until a parent element for which the provided
'until' function is truthy. Basic implementation from http://stackoverflow.com/a/5776220/430128.
@param elem
@param until A function, if provided, is passed each parent element and computed style. If it returns a
  truthy value, the returned position will be relative to that element.
@returns {{x: number, y: number}}