0.1.1 • Published 5 years ago

@jfm/scrollspy v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

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