1.0.1 • Published 7 years ago
resize-scroll-handler v1.0.1
resize-scroll-handler
A package within web-sparkle.
No more long frames. Stop repainting the browser all the time, and only fire window events once.
Usage
$ npm install resize-scroll-handler
const ResizeScrollHandler = require('resize-scroll-handler')
const handler = new ResizeScrollHandler()
// Add as many callbacks as you want without performing unnecessary
// browser reflows or taking up extra memory. Woohoo!
handler.addToHandler('resize', resizeCallback)
handler.addToHandler('resize', anotherResizeCallback)
handler.addToHandler('resize', yetAnotherResizeCallback)
...
handler.addToHandler('scroll', scrollCallback)
handler.addToHandler('scroll', anotherScrollCallback)
handler.addToHandler('scroll', yetAnotherScrollCallback)
...
handler.requestResize()
handler.requestScroll()
Reference
ResizeScrollHandler.requestResize()
Trigger all the resize handlers.
ResizeScrollHandler.requestSCroll()
Trigger all the scroll handlers.
ResizeScrollHandler.addToHandler(type, fn)
Add an event handler.
Params
- type
String
- Either 'resize' or 'scroll'. - fn
Function
- The function you'd like to add on to the event handler.
Development
To run the example locally, run the following commands:
npm install
npm run dev
npm start
Credits
This readme is maintained by hello@christinecha.com.
License
MIT