UNPKG

react-anchor-navigation

Version:

React lightweight library for anchor scrolling and navigation tied to URL hash.

17 lines (13 loc) 351 B
import { TStore } from "../components/AnchorProvider"; export const getElementScrollPosition = ( element: HTMLElement, scroller: TStore["scroller"] ): number => { let y = 0; let el: HTMLElement | null = element; do { y += el.offsetTop; el = el.offsetParent as HTMLElement | null; } while (el && el !== scroller); return y; };