InView
The manGoweb InView component. Watches elements entering and leaving viewport.
Installation
npm install @mangoweb/in-view @mangoweb/scripts-base
This is a @mangoweb/scripts-base
component.
Usage
In your template:
<script>
window.initComponents = (window.initComponents || []).push({
name: 'InView',
place: '#targetWrapper',
data: {
targets: '.target',
threshold: 0,
isAboveViewClass: 'isAboveView',
isInViewClass: 'isInView',
isBelowViewClass: 'isBelowView',
isSeenClass: 'isSeen',
}
})
</script>
IE support / older Safari (caniuse)
Use IntersectionObserver
polyfill, e.g., <script src="https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserver"></script>