-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.js
48 lines (40 loc) · 982 Bytes
/
utils.js
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
38
39
40
41
42
43
44
45
46
47
48
export function create(type, attributes = {}){
let element = document.createElement(type);
try{
Object.keys(attributes).forEach(attr => {
element.setAttribute(attr, attributes[attr]);
})
} catch(err){
console.error(err)
}
return element;
}
export class Events{
listeners = [];
addEvent(el, e, fn, capture){
el && el.addEventListener(e, fn, capture);
this.listeners.push({el, fn, e})
}
destroyAll(){
this.listeners.forEach( l =>{
if(l && l.el) {
l.el.removeEventListener(l.e, l.fn)
}
})
}
}
export function dispatchEvent(target, type, details) {
let event = new CustomEvent(
type,
{
bubbles: true,
cancelable: true,
details: details
}
);
target.dispatchEvent(event);
}
export const requestAnimationFrame = window.requestAnimationFrame
|| window.mozRequestAnimationFrame
|| window.webkitRequestAnimationFrame
|| window.msRequestAnimationFrame;