@f/offset-parent
v1.0.1
Published
Find the offset parent of a DOM element
Downloads
21
Readme
offset-parent
Find the offset parent of a DOM element
Installation
$ npm install @f/offset-parent
Usage
The offset parent of a given element is the first parent up the tree that is positioned absolute
, relative
, or fixed
.
var offsetParent = require('@f/offset-parent')
function position (node, placement) {
var parent = offsetParent(node)
node.style.left = (parent.offsetWidth / 2) - (node.offsetWidth / 2) + 'px'
switch (placement) {
case 'top':
node.style.top = -node.offsetHeight + 'px'
break
case 'bottom':
node.style.bottom = '0px'
break
}
}
API
offsetParent(node)
node
- The DOM node who's offsetParent you want to find
Returns: The first node above node
that is positioned absolute
, relative
, or fixed
.
License
MIT