The Intersection Observer API provides a way to asynchronously observe changes in the intersection of a target element with an ancestor element or with a top-level document's viewport.
It is much more efficient and its polyfill is very simple for browsers which do not support it that its code is already in this library
https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API
It is much more efficient and its polyfill is very simple for browsers which do not support it that its code is already in this library