Skip to content

arlegotin/element-size-observer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published