This version is old school.
Please find jQuery plugins on npm.
jQuery.PositionCalculator
Calculate the position of an element relative to another element or event. It has also functionality to handle collision within the viewport of a given container. It does not manipulate CSS or DOM, it only calculates values. It is a basic technology to support implementation of tooltips, popups, popovers, scrollspies, sticky navi and many more.