Skip to content

antinomy-studio/size

Repository files navigation

size.js

⚠️ This is a fork from @ayamflow's repository. https://github.com/ayamflow/size

Small util to centralize and debounce window 'resize' events.

  • Avoid accessing a global object (window)
  • Avoid triggering unnecessary repaint/reflow
  • Avoid locking the UI by only dispatching one event

Install

npm install @antinomy-studio/size --save

Usage

import size from 'size'

size.addListener((width, height) => {
  console.log({ width, height })
})

console.log(size.width)

Instance Methods

addListener(handler[, context])

Bind a function to the resize event

  • handler - the function to call after a resize event
  • context - (OPTIONAL) - the context to bind the event callback to

removeListener(handler[, context])

Unbind a function to the resize event

  • handler - the function to call after a resize event
  • context - (OPTIONAL) - the context to bind the event callback to

bind(options)

Enable the singleton by listen to the window onresize event.

  • options - a hash containing configurable options:
  • debounceTime: debounce delay for the window onresize event. Defaults is 150.

unbind()

Unbind the window onresize event.

Instance Properties

width

height

isLandscape

hasBar (experimental)

true on mobile if the browser bar is shown on iOS.

License

MIT.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published