Scrollspy using IntersectionObserver
npm install @jfm/scrollspyZero dependencies scrollspy library using the Intersection Observer API.
```
npm install @jfm/scrollspy
`js
import scrollspy from '@jfm/scrollspy'
// or
// import { observe, unobserve } from '@jfm/scrollspy'
const el = document.getElementById('section')
function callback(el) {
console.log('scrolled to', el)
}
scrollspy.observe(el, callback)
`
`js`
observe(element, callback)
Observe the element, call the callback when it comes into the viewport.
You can call it multiple times with different callbacks.
`js`
unobserve(element, [callback])
Unobserve the element with callback. If callback` is not defined, remove all the callbacks.