Skip to content

Commit 20a0ef9

Browse files
committed
readme
1 parent c080e01 commit 20a0ef9

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# simple-element-resize-detector
2+
3+
Observes resizing of an element using a hidden iframe.
4+
5+
6+
## Installation
7+
8+
```sh
9+
npm i -S simple-element-resize-detector
10+
```
11+
12+
13+
## Usage
14+
15+
```js
16+
import observeResize from 'simple-element-resize-detector';
17+
18+
// any DOM element that can have children
19+
let element = document.createElement('div');
20+
21+
// listen for resize
22+
observeResize(element, () => {
23+
console.log('new size: ', {
24+
width: element.clientWidth,
25+
height: element.clientHeight
26+
});
27+
});
28+
```
29+
30+
To stop observing resize events, simply remove the returned detector frame:
31+
32+
```js
33+
let detector = observeResize(el, () => {});
34+
35+
detector.remove();
36+
37+
// or, for better browser compatibility:
38+
// detector.parentNode.removeChild(detector)
39+
```
40+
41+
## License
42+
43+
MIT

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default (element, handler) => {
55
frame.style.cssText = CSS;
66
element.appendChild(frame);
77
frame.contentWindow.onresize = () => {
8-
handler.call(element);
8+
handler(element);
99
};
1010
return frame;
1111
}

0 commit comments

Comments
 (0)