0.5.0 • Published 9 years ago
manage-scroll-handlers v0.5.0
manage-scroll-handlers
Add and remove scroll handlers to any DOM nodes. Doesn't block the event loop, and creates as few actual handlers as possible.
Installation
$ npm install --save manage-scroll-handlers
Usage
With import statement:
import { addScrollHandler, removeScrollHandler } from 'manage-scroll-handlers';
// Add scroll handler to window
addScrollHandler(() => console.log('1'));
addScrollHandler(() => console.log('2'));
// Add scroll handler to another element
addScrollHandler(() => console.log('3'), document.getElementById('scrollable-wrapper'));
// Add and remove scroll handlers
const callback = () => console.log('4');
addScrollHandler(callback);
removeScrollHandler(callback);
If you don't have import
statements available, you can also do:
const { addScrollHandler, removeScrollHandler } = require('manage-scroll-handlers').default;
If you're stuck without babel at all, I don't envy you, but you can do this:
var manageScrollHandlers = require('manage-scroll-handlers').default;
var addScrollHandler = manageScrollHandlers.addScrollHandler;
var removeScrollHandler = manageScrollHandlers.removeScrollHandler;
License
MIT © Ben Berman