@jfm/scrollspy

0.1.1 • Public • Published

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

Package Sidebar

Install

npm i @jfm/scrollspy

Weekly Downloads

16

Version

0.1.1

License

MIT

Unpacked Size

35.7 kB

Total Files

8

Last publish

Collaborators

  • jiangfengming