events.ts
1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-11-28 17:15:38
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2023-12-14 14:58:34
* @FilePath: \glsx-tracker-javascript\src\modules\clickEvent.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
class Events {
/**
* 给元素添加事件,并注册事件
* @param element 接收的数据
*/
addEvent(element: HTMLElement | Window, type: string, handler: Function) {
this.registerEvent(element, type, handler)
}
/**
* 注册事件,并绑定事件
* @param element,元素
* @param type 事件名
* @param handler 事件回调
*/
registerEvent(element: HTMLElement | Window, type: string, handler: Function) {
let useCapture = false
if (type === 'click') {
useCapture = true
}
element.addEventListener(
type,
e => {
handler.call(this, e)
},
useCapture
)
}
}
export default new Events()