The Intersection Observer API provides a better way of finding the position of an element.

Read on afasterweb.com