observe-resize
v1.1.3
Published
Trigger a callback when an element is resized
Downloads
47
Readme
observe-resize
Trigger a callback when an element is resized. Adapted from simple-element-resize-detector.
Usage
var observeResize = require('observe-resize')
var html = require('bel')
var el = html`<div>hello planet</div>`
document.body.appendChild(el)
// observers should only be added _after_ the element is rendered on the DOM,
// else it displeases the browser emperors and they _will_ warn you
var stop = observeResize(el, function () {
console.log('resized')
stop()
})
API
stopObserving = observeResize(el, callback)
Observe resize events on the specified element. This event is throttled by
requestAnimationFrame
. In most cases you'd probably still want to use a
debounce
function to throttle changes, as resize events can be rather
volatile otherwise.
stopObserving
Unbind the observer from the element.
Installation
$ npm install observe-resize