Socket
Socket
Sign inDemoInstall

position.js

Package Overview
Dependencies
0
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    position.js

Positions a popup element to an anchor element.


Version published
Maintainers
1
Install size
37.7 kB
Created

Changelog

Source

1.1.0 (2023-12-10)

Features

  • add boundary option (25fdd99)
  • add types, export Rect/Point (6ba1145)

Readme

Source

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')

Keywords

FAQs

Last updated on 10 Dec 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc