viewprt 
A tiny, high performance viewport position & intersection observation tool. You can watch when elements enter & exit the viewport, or when the viewport itself is at the bottom or top. Use this as a building block for things such as lazy loaders, infinite scrollers, etc.
Install
yarn add viewprt
API
Create new observers and any time its container is scrolled, resized, or mutated, the appropriate callbacks will be triggered when the condition is met.
import { PositionObserver, ElementObserver } from 'viewprt'
const element = document.getElementById('element')
const elementObserver = ElementObserver(element, {
container: document.body,
offset: 0,
once: false,
onEnter (element, viewportState) {},
onExit (element, viewportState) {}
})
const positionObserver = PositionObserver({
container: document.body,
offset: 0,
once: false,
onBottom (container, viewportState) {},
onTop (container, viewportState) {},
onMaximized (container, viewportState) {}
})
positionObserver.destroy()
elementObserver.destroy()
positionObserver.activate()
elementObserver.activate()
Build
yarn build
Test
yarn test