https://github.com/yukiniro/obsize
🧐 Element size observer based on ResizeObserver
https://github.com/yukiniro/obsize
element-size observer resize resizeobserver sensor
Last synced: 10 months ago
JSON representation
🧐 Element size observer based on ResizeObserver
- Host: GitHub
- URL: https://github.com/yukiniro/obsize
- Owner: Yukiniro
- License: mit
- Created: 2023-05-17T07:26:13.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-05-24T15:15:32.000Z (about 3 years ago)
- Last Synced: 2025-06-26T12:52:16.012Z (about 1 year ago)
- Topics: element-size, observer, resize, resizeobserver, sensor
- Language: TypeScript
- Homepage:
- Size: 246 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# obsize
`obsize` is a tiny library that observes an element's size change.
## [Browser Compatibility](https://developer.mozilla.org/en-US/docs/Web/API/Resize_Observer_API#browser_compatibility)
- Chrome (64+)
- Edge (79+)
- Firefox (69+)
- Opera (51+)
- Safari (13.1+)
## Install
```shell
pnpm add obsize -S
npm install obsize -S
yarn add obsize -S
```
## Useage
```javascript
import { observe } from "../../src/index";
const unobserve = observe(element, () => { console.log('trigger') });
// call unobserve could remove the observe
unobserve()
```
## API
### `observe`
Observe the size of specified elements.
- Params
- `element` - The element to be observer.
- `fn` - The function to call when the element's size has changed.
- `options` - Others cofnig.
- `once` - It will auto-remove the observer when `fn` has been called.
### `clear`
Clear all observers for any elements.
## License
MIT license.