Wrapper of IntersectionObserver
npm install intersection-eventsIntersectionObserverYou can detect when the whole element enters and leaves window.
``sh`
npm i intersection-events
`js`
import IntersectionEvents from 'intersection-events'
`html`
`js`
new IntersectionEvents('.js-target', {
onEnter: el => {
// When the whole element enters window
},
onLeave: el => {
// When the whole element leaves window
}
})
`html
If you want to detect enter only once, set
isOnce option to true.`js
new IntersectionEvents('.js-target', {
onEnter: el => {
// Do only once
},
isOnce: true
})
`Browsers support
|
Edge |
Firefox |
Chrome |
| --------- | --------- | --------- |
| Edge| last version| last version
$3
If you need to support browsers that do not support
IntersectionObserver, load the IntersectionObserver polyfill.If the
IntersectionObserver` polyfill is loaded, browsers support is as follows.|
IE / Edge |
Firefox |
Chrome |
Safari |
iOS Safari |
| --------- | --------- | --------- | --------- | --------- |
| IE11, Edge| last version| last version| last version| last version
---
If you want more features, please consider other libraries.