element-size-observer
v1.0.2
Published
Minimalistic wrapper around ResizeObserver to watch element size
Downloads
2
Maintainers
Readme
ElementSizeObserver
Minimalistic wrapper around ResizeObserver to watch element size.
Installation
# via npm:
npm i element-size-observer
# or yarn:
yarn add element-size-observer
Usage
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
.
Contribution
Feel free to open issues and pull-requests.