Socket
Socket
Sign inDemoInstall

position-element

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    position-element

A simple function for positioning one DOM element relative to another DOM element


Version published
Maintainers
1
Install size
52.0 kB
Created

Readme

Source

position-element

A simple function for positioning one DOM element relative to another DOM element (anchor element).

It is useful for implementing something like tooltips, dropdown/popups with support for these features:

  1. Automatically reposition element with best alternative placement if element renders out of browser view port.
  2. Supports 12 placements options.
  • up-left, up-center, up-right
  • down-left, down-center, down-right
  • left-top, left-middle, left-bottom
  • right-top, right-middle, right-bottom
  1. Customizable distance and offset

Example

import positionElement from 'position-element';

const config = {
  element: document.getElementById('subject'),
  anchorElement: document.getElementById('anchor'),
  preferredPlacement: 'down-center',
  distance: 10,
  alignmentOffset: 0,
  autoReposition: true,
};

positionElement(config);


Live demo

demo.html

Tips

  1. positionElement will do the measurement and set element's position: absolute, left and top style for you.
  2. However, it is important for you to set the right position style (e.g. position:relative ) for the common container of both the anchor element and the positioning element.

Keywords

FAQs

Last updated on 28 Feb 2018

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