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
npm install watsondg/size -S
var size = require('size');
size.addListener(function(width, height) {
console.log('resized', width, height);
});
console.log(size.width);
Bind a function to the resize event
handler
- the function to call after a resize eventcontext
- (OPTIONAL) - the context to bind the event callback to
Unbind a function to the resize event
handler
- the function to call after a resize eventcontext
- (OPTIONAL) - the context to bind the event callback to
Enable the singleton by listen to the window onresize
event.
options
- a hash containing configurable options:
debounceTime
: debounce delay for the windowonresize
event. Defaults is 150.
Unbind the window onresize
event.
true on mobile if the browser bar is shown on iOS.
MIT.