A simple function for positioning one DOM element relative to another DOM 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:
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);
positionElement will do the measurement and set element’s position: absolute, left and top style for you.position style (e.g. position:relative ) for the common container of both the anchor element and the positioning element.