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

编程之道

编程之道

杰弗雷﹒詹姆斯 / 清华大学出版社 / 1999-05 / 18.00元

本书出自美国一位善于进行哲学思考、有十多年工作经验的程序设计师——杰弗雷·詹姆斯之手,他以一种敏锐的眼光审视着发生在程序设计室里的各种各样的小故事,并利用古老的道家思想对其进行分析。简单的故事蕴含深奥的道理,是本书的最大特色。本书语言优美,比喻生动,可读性极强。一起来看看 《编程之道》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码