size-sensor
DOM element size sensor which will callback when the element size changed.
DOM 元素尺寸监听器,当元素尺寸变化的时候,将会触发回调函数!
Install
npm i --save size-sensor
Then import it.
import { bind, clear } from 'size-sensor';
or import it by script
in HTML, then get sizeSensor
on window.
<script src="https://unpkg.com/size-sensor/dist/size-sensor.min.js"></script>
Usage
import { bind, clear } from 'size-sensor';
const unbind1 = bind(document.querySelector('.container'), element => {
});
const unbind2 = bind(document.querySelector('.container'), element => {
});
unbind1();
import { bind, clear } from 'size-sensor';
clear(element);
API
There is only 2 API:
Bind the resize trigger function on element. The function will return unbind
function.
Clear all the object and resize event on element.
Strategies
The size sensor strategies include:
-
object
: use object document's resize event.
## Reference
Online demo click [here](https://git.hust.cc/size-sensor). Rewritten and optimized from [KyleAMathews/element-resize-event](https://github.com/KyleAMathews/element-resize-event).
Used By:
- [hustcc/echarts-for-react](https://github.com/hustcc/echarts-for-react)
- [hustcc/canvas-nest.js](https://github.com/hustcc/canvas-nest.js)
- [hustcc/gantt-for-react](https://github.com/hustcc/gantt-for-react)
# License
ISC@[hustcc](https://github.com/hustcc).