当前位置:主页 > 资料 >

size-sensor:开源高性能 DOM 元素尺寸监听器
栏目分类:资料   发布日期:2018-08-01   浏览次数:

导读:本文为去找网小编(www.7zhao.net)为您推荐的size-sensor:开源高性能 DOM 元素尺寸监听器,希望对您有所帮助,谢谢! DOM element size sensor which will callback when the element size changed.DOM 元素尺寸监

本文为去找网小编(www.7zhao.net)为您推荐的size-sensor:开源高性能 DOM 元素尺寸监听器,希望对您有所帮助,谢谢! 欢迎访问www.7zhao.net



DOM element size sensor which will callback when the element size changed.
DOM 元素尺寸监听器,当元素尺寸变化的时候,将会触发回调函数!
 去找(www.7zhao.net欢迎您 

内容来自www.7zhao.net

Install

npm i --save size-sensor
 内容来自www.7zhao.net 

Then import it.

欢迎访问www.7zhao.net

import { bind, clear } from 'size-sensor'; 去找(www.7zhao.net欢迎您 

or import it by script in HTML, then get sizeSensor on window. copyright www.7zhao.net

<script src="https://unpkg.com/size-sensor/dist/size-sensor.min.js"></script> 

本文来自去找www.7zhao.net

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(); 
www.7zhao.net
  • 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); 内容来自www.7zhao.net 

API

There is only 2 API: 欢迎访问www.7zhao.net

  • bind(element, callback)

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

欢迎访问www.7zhao.net

  • clear(element)

Clear all the object and resize event on element. www.7zhao.net

Strategies

The size sensor strategies include:

www.7zhao.net

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

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

内容来自www.7zhao.net

Reference

Online demo click . Rewritten and optimized from .

内容来自www.7zhao.net

Used By:

内容来自www.7zhao.net

License

ISC@ .

内容来自www.7zhao.net

内容来自www.7zhao.net


本文原文地址:https://github.com/hustcc/size-sensor

以上为size-sensor:开源高性能 DOM 元素尺寸监听器文章的全部内容,若您也有好的文章,欢迎与我们分享! 欢迎访问www.7zhao.net

Copyright ©2008-2017去找网版权所有   皖ICP备12002049号-2 皖公网安备 34088102000435号   关于我们|联系我们| 免责声明|友情链接|网站地图|手机版