# resize-event

> Detect resize on an element without polling or iframes

Latest version **2.0.1** (published 2023-07-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install resize-event
pnpm add resize-event
yarn add resize-event
bun add resize-event
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2023-07-24 |
| First published | 2015-07-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | Kyle Robinson Young |
| Maintainers | shama |
| Keywords | resize, event, element |

## Links

- npm: https://www.npmjs.com/package/resize-event
- Repository: https://github.com/shama/resize-event
- Homepage: https://github.com/shama/resize-event#readme
- Issues: https://github.com/shama/resize-event/issues
- npm.io page: https://npm.io/package/resize-event

## Dependencies (1)

- [mutationobserver-shim](https://npm.io/package/mutationobserver-shim.md) ^0.3.5

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 2.0.1 (latest) — 2023-07-24
- 2.0.0 — 2020-06-04
- 1.2.1 — 2018-10-29
- 1.2.0 — 2018-10-29
- 1.1.0 — 2015-07-23
- 1.0.1 — 2015-07-23
- 1.0.0 — 2015-07-23

## README

# resize-event
Detect resize on an element without polling or iframes

[![build status](https://secure.travis-ci.org/shama/resize-event.svg)](https://travis-ci.org/shama/resize-event)
[![NPM version](https://badge.fury.io/js/resize-event.svg)](https://badge.fury.io/js/resize-event)

If the browser supports [`ResizeObserver`](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver) this will use that otherwise it will fallback to a [MutationObserver](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver)
to detect changes to the `style` attribute of an element and then compares the
width/height to check if it has changed.

A polyfill is provided for `MutationObserver` which will then use polling on really old browsers.

## usage

```js
import onResize from "resize-event"

// Create or select an element, must be in the DOM
const element = document.createElement('div')
document.body.appendChild(element)

// Bind the event
const observer = onResize(element, () => {
  console.log('element was resized', element.offsetWidth, element.offsetHeight)
})

// Trigger the event
element.style.width = '500px'

// Later disconnect the event
observer.disconnect()
```

## install

```shell
npm install resize-event --save
```

# license

(c) 2020 Kyle Robinson Young. MIT License

---
_Source: https://npm.io/package/resize-event · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
