DOM 元素尺寸监听器 size-sensor

码农软件 · 软件分类 · 常用JavaScript包 · 2019-04-04 14:43:51

软件介绍

size-sensor

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

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

安装

npm i --save size-sensor

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

或者使用 script 引入,将得到一个全局变量 sizeSensor.


使用

  • 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

只有 2 API:

  • bind(element, callback)

绑定一个 reisze 监听方法到 DOM 元素上,调用直接返回 unbind 方法。

  • clear(element)

清楚 DOM 元素上的所有 resize 监听器函数。

Reference

Online demo click here. Rewrite from KyleAMathews/element-resize-event, will be used on hustcc/echarts-for-react.

License

ISC@hustcc.

本文地址:https://codercto.com/soft/d/2846.html

算法技术手册

算法技术手册

George T. Heineman、Gary Pollice、Stanley Selkow / 杨晨、李明 / 机械工业出版社 / 2010-3 / 55.00元

《算法技术手册》内容简介:开发健壮的软件需要高效的算法,然后程序员们往往直至问题发生之时,才会去求助于算法。《算法技术手册》讲解了许多现有的算法,可用于解决各种问题。通过阅读它,可以使您学会如何选择和实现正确的算法,来达成自己的目标。另外,书中的数学深浅适中,足够使您可以了解并分析算法的性能。 较之理论而言,《算法技术手册》更专注于应用。《算法技术手册》提供了高效的代码解决方案,使用多种语言......一起来看看 《算法技术手册》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

在线进制转换器
在线进制转换器

各进制数互转换器

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器