1.0.1 • Published 3 years ago

@daun/scroll-manager v1.0.1

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

Scroll Manager

Smooth scroll handlers.

  • Uses requestAnimationFrame to achieve smooth scrolling while running callbacks.
  • Listens for a scroll event listener to start the animation loop.
  • Stops the animation loop once the user has stopped scrolling.

See How to make faster scroll effects? for the thinking behind this approach and tylerchild's gist for the original implementation.

Usage

Create a Scroll Manager, ideally one per page, using createScrollManager().

  • add(callback: function(scrollPosition)) - Add a callback function to be fired every animation loop
  • remove(callback: function) - Remove a callback function from the Scroll Manager
  • destroy() - Kill the Scroll Manager
import createScrollManager from '@daun/scroll-manager'

const log1 = console.log.bind(null, 1)
const log2 = console.log.bind(null, 2)
const log3 = console.log.bind(null, 3)

const scrollManager = createScrollManager()

scrollManager.add(log1)
scrollManager.add(log2)
scrollManager.add(log3)

scrollManager.remove(log1)

setTimeout(scrollManager.destroy, 5000)

License

MIT