manage-scroll-handlers

0.5.0 • Public • Published

manage-scroll-handlers NPM version Dependency Status

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

Readme

Keywords

Package Sidebar

Install

npm i manage-scroll-handlers

Weekly Downloads

0

Version

0.5.0

License

MIT

Last publish

Collaborators

  • rivertam