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

白帽子讲Web安全(纪念版)

白帽子讲Web安全(纪念版)

吴翰清 / 电子工业出版社 / 2014-6 / 69.00元

互联网时代的数据安全与个人隐私受到前所未有的挑战,各种新奇的攻击技术层出不穷。如何才能更好地保护我们的数据?《白帽子讲Web 安全(纪念版)》将带你走进Web 安全的世界,让你了解Web 安全的方方面面。黑客不再神秘,攻击技术原来如此,小网站也能找到适合自己的安全道路。大公司如何做安全,为什么要选择这样的方案呢?在《白帽子讲Web 安全(纪念版)》中都能找到答案。详细的剖析,让你不仅能“知其然”,......一起来看看 《白帽子讲Web安全(纪念版)》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

html转js在线工具
html转js在线工具

html转js在线工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具