offsetParent.js 465 Bytes
Newer Older
Sangjune Bae's avatar
Sangjune Bae committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import css from './css';
import ownerDocument from './ownerDocument';

var isHTMLElement = function isHTMLElement(e) {
  return !!e && 'offsetParent' in e;
};

export default function offsetParent(node) {
  var doc = ownerDocument(node);
  var parent = node && node.offsetParent;

  while (isHTMLElement(parent) && parent.nodeName !== 'HTML' && css(parent, 'position') === 'static') {
    parent = parent.offsetParent;
  }

  return parent || doc.documentElement;
}