npm.io
0.1.1 • Published 7 years ago

@jfm/scrollspy

Licence
MIT
Version
0.1.1
Deps
0
Size
35 kB
Vulns
0
Weekly
0
Stars
2

scrollspy

Zero dependencies scrollspy library using the Intersection Observer API.

Demo

Install

npm install @jfm/scrollspy

Usage

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)

APIs

observe
observe(element, callback)

Observe the element, call the callback when it comes into the viewport. You can call it multiple times with different callbacks.

unobserve
unobserve(element, [callback])

Unobserve the element with callback. If callback is not defined, remove all the callbacks.

License

MIT

Keywords