1.0.1 • Published 8 years ago

@f/offset-parent v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

offset-parent

Build status Git tag NPM version Code style

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