0.0.1 • Published 6 years ago

evented-viewport v0.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

evented-viewport

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

Viewport width and height utility for JavaScript modules.

Install

$ npm i evented-viewport --save

Usage

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

import knot from 'knot.js'
import viewport from 'evented-viewport'

// have your emitter handy (create or import one)
const emitter = knot()

// (optionally) subscribe to the resize event
// note that all handlers will be passed an object containing the viewport width/height
emitter
  .on('resize', viewport => console.log(`width: ${ viewport.width }`))
  .on('resize', viewport => console.log(`height: ${ viewport.height }`))

// define your options
const options = {
  debounce: 250,      // time, in ms, that must pass before updating the viewport width/height on resize
  emitter             // object with an "emit" method
}

// create an instance (should be a singleton)
const instance = viewport(options)

// export (and enjoy in other modules)
export default instance

See Also

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

License

MIT. © 2017 Michael Cavalea