1.0.2 • Published 2 years ago

size-sensor v1.0.2

Weekly downloads
61,116
License
ISC
Repository
github
Last release
2 years ago

size-sensor

DOM element size sensor which will callback when the element size changed.

DOM 元素尺寸监听器,当元素尺寸变化的时候,将会触发回调函数!

Build Status npm npm gzip

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

  • bind & unbind
import { bind, clear } from 'size-sensor';

// bind the event on element, will get the `unbind` function
const unbind1 = bind(document.querySelector('.container'), element => {
  // do what you want to to.
});

const unbind2 = bind(document.querySelector('.container'), element => {
  // do what you want to to.
});

// if you want to cancel bind event.
unbind1();
  • clear
import { bind, clear } from 'size-sensor';

/*
 * // bind the resize event.
 * const unbind1 = bind(...);
 * const unbind2 = bind(...);
 * ...
 */

// you can cancel all the event of element.
clear(element);

API

There is only 2 API:

  • bind(element, callback)

Bind the resize trigger function on element. The function will return unbind function.

  • clear(element)

Clear all the object and resize event on element.

Strategies

The size sensor strategies include:

  • ResizeObserver: use resizeObserver to observe element's size.
  • object: use object document's resize event.

If ResizeObserver exists, use it, else use object as default.

Let me know

Online demo click here. Used By:

License

ISC@hustcc.

@echarts-wrapper/react@tcljs/g2plotcchartsucocharts@infinitebrahmanuniverse/nolb-sizxdcorewired-echarts-for-reactwd-echarts-reactxdcorelibxdcorewebxm-charts-reactxm-react-chartsxh-toolsupcon-libjylibg-echarts-reactuedchartstui-base@antv-source/g2plot@antv/dumi-theme-antv@antv/gi-assets-advance@antv/g2plot@aliyun-sls/components@aliyun-sls/logsearch@agito/chart-core@cherie-xf/lit-echarts@daykalif/g2plot-sankeyyys-form-makingwc-g2unicom-tarozn-echarts-reactzl-charts@grc/base@hedou/echart@hulujs/met@gm-pc/vision@lingxiteam/pcfactory@liyuanqiu/echarts-for-svelte@logicflow/dumi-theme-simple@everything-registry/sub-chunk-2773@meta-ultra/ui@mj-jadhav/echarts-for-react@koi-design/vix-charts@kaiei/echart-react-components@okeev/chartsmre-metmycompoinssola-uipargo-maprs-chartsrootnet-uirc-size-sensorreact-gplotreact-gpplotreact-g6react-for-echartspsy-test-resultsmartcity-map-v3react-sam-scrollbarggabcd-echarts-for-reactggabcd-for-reactgt-echarts-for-reactlighting-designmasterrtmap-supconit@we-weaver/biz-component-prescription@yyr1994/h-charts@zjlabvis/vis-chartscanvas-line.jscanvas-nest-fixedcanvas-nest.jscloud-react-echartsd3-vsdatav-g2plot-adaptordatabend-profile-uidf-screen-component-libecharts-react-v2echarts-for-react-winnerecharts-for-scooperecharts-for-svelteecharts-for-svelte2echarts-next-for-reactecharts-for-reactecharts-for-react-gsopecharts-for-react-hotfix302echarts-for-react-irecharts-for-react-pixecharts-for-react-v5fed-react-compflarejgantt-for-reactgantt-for-react-typescriptgantt-react-typescript-vendoredg2plot-vnptg2-for-reactg-lowcode-components
1.0.2

2 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

7 years ago

0.2.2-beta.1

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago