position.js
Positions a popup element to an anchor element.
Last updated 6 years ago by ambarli .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install position.js 
SYNC missed versions from official npm registry.

position.js

Positions a popup element to an anchor element 😉

npm version minzipped size Greenkeeper badge

Demo

position.js

Usage

const {
  placement, // actual placement
  popupOffset, // CSS position: {left, top}
  arrowOffset, // CSS position: {left, top}
  popupRect,
  anchorRect,
} = position(popup, anchor, 'top', options)

// DOM
Object.assign(popup.style, popupOffset)

// React
<Popup style={popupOffset} arrowOffset={arrowOffset} placement={placement} />

API

position(popup, anchor, placement, options)

Options

{
  // use fixed or absolute position, defaults to false
  fixed: false,
  // any scroller element, defaults to document.body
  offsetParent: document.body,
  // 'auto': adjusts horizontally or vertically, 'both': adjusts horizontally and vertically, defaults to 'none'
  adjustXY: 'none',
}

Placement Presets

  • top
  • right
  • bottom
  • left
  • center
  • top-left
  • top-right
  • right-top
  • right-bottom
  • bottom-left
  • bottom-right
  • left-top
  • left-bottom

Placement Combos

position(popup, anchor, {popup: 'left-top', anchor: 'right-top'})
// same as `right-top` placement
position(popup, anchor, 'right-top')

Current Tags

  • 1.1.0                                ...           latest (a year ago)

13 Versions

  • 1.1.0                                ...           a year ago
  • 1.0.0                                ...           a year ago
  • 0.3.0                                ...           6 years ago
  • 0.2.4                                ...           7 years ago
  • 0.2.3                                ...           7 years ago
  • 0.2.2                                ...           8 years ago
  • 0.2.1                                ...           8 years ago
  • 0.2.0                                ...           8 years ago
  • 0.1.1                                ...           8 years ago
  • 0.1.0                                ...           8 years ago
  • 0.0.3                                ...           8 years ago
  • 0.0.2                                ...           8 years ago
  • 0.0.1                                ...           8 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (10)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE