Minimalistic wrapper around ResizeObserver to watch element size.
# via npm:
npm i element-size-observer
# or yarn:
yarn add element-size-observer
Basic example:
import ElementSizeObserver from 'element-size-observer'
const observer = new ElementSizeObserver({
element: document.querySelector('#some'),
onResize: element => {
console.log('Element resized')
},
})
ElementSizeObserver
inherits EventEmitter interface, so you can subscribe to resize
event:
const observer = new ElementSizeObserver({
element: document.querySelector('#some'),
})
observer.on('resize', element => {
console.log('Handler #1')
})
observer.once('resize', element => {
console.log('Handler #2')
})
observer.removeAllListeners()
Destroy the instance when it's no longer needed:
observer.destructor()
Destructor will properly destroy underlying ResizeObserver
and EventEmitter
.
Feel free to open issues and pull-requests.