Giter VIP home page Giter VIP logo

t-entrust's Introduction

t-entrust

便捷的事件委托代理

t-entrust 是封装了事件委托的一个简单插件,配合 data- 自定义属性就能够完成监听器的委托

安装

npm i -S t-entrust

使用

<!-- html -->

<!-- 通过 data-entrust 指定要操作的 dom -->
<!-- data-entrust 的值表示你要做什么操作 -->
<section id="wrap">
	<button data-entrust="copy">copy</button>
</sectioin>
// js
import TEntrust from "t-entrust"

let wrap = new TEntrust("wrap") // 使用 wrap 而不是 #wrap

上面例子表示:

  • 首先给要监听的父元素定义 id
  • 给 button 按钮添加了一个自定义属性,并赋值为 copy
let wrap = new TEntrust("wrap")
// listen 第一个参数为要监听的事件
// 第二个参数为 回调函数,该回调函数的参数为默认的 event
// 通过 getName函数 来获取响应的操作
// getName 第一个参数为 event,第二个参数为设置监听的事件标签名
// 并返回设置了 data-entrust 的值
wrap.listen("click", e => {
	let copy = wrap.getName(e, "button")
	// do somethings
})

��� 对于经常使用的监听方式,如:click ,默认提供了几个函数可以简化操作:

  • click
  • mousemove
  • scroll
let wrap = new TEntrust("wrap")
wrap.click(e => {
	// do something
})

移除监听器:

wrap.destroy()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.