项目作者: callmecavs

项目描述 :
Viewport width and height utility for JavaScript modules.
高级语言: JavaScript
项目地址: git://github.com/callmecavs/evented-viewport.git
创建时间: 2017-11-17T00:42:49Z
项目社区:https://github.com/callmecavs/evented-viewport

开源协议:

下载


evented-viewport

evented-viewport on NPM evented-viewport Downloads on NPM Standard JavaScript Style

Viewport width and height utility for JavaScript modules.

Install

  1. $ npm i evented-viewport --save

Usage

Pass evented-viewport an options object with debounce and emitter properties:

  1. import knot from 'knot.js'
  2. import viewport from 'evented-viewport'
  3. // have your emitter handy (create or import one)
  4. const emitter = knot()
  5. // (optionally) subscribe to the resize event
  6. // note that all handlers will be passed an object containing the viewport width/height
  7. emitter
  8. .on('resize', viewport => console.log(`width: ${ viewport.width }`))
  9. .on('resize', viewport => console.log(`height: ${ viewport.height }`))
  10. // define your options
  11. const options = {
  12. debounce: 250, // time, in ms, that must pass before updating the viewport width/height on resize
  13. emitter // object with an "emit" method
  14. }
  15. // create an instance (should be a singleton)
  16. const instance = viewport(options)
  17. // export (and enjoy in other modules)
  18. export default instance

See Also

  • knot.js - A browser-based event emitter, for tying things together.

License

MIT. © 2017 Michael Cavalea