-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEasyDOM.js
More file actions
152 lines (143 loc) · 4.12 KB
/
Copy pathEasyDOM.js
File metadata and controls
152 lines (143 loc) · 4.12 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
let is_running = null;
let queue = [];
function $(selector) {
const el = document.querySelector(selector);
function queueFunc() {
while (queue.length) {
let func = queue.shift();
setTimeout(() => {
func.call.apply(null, func.params);
}, 100);
}
}
function isRunning(func, arguments = {}, callback) {
if (is_running) {
queue.push({ call: func, params: Object.values(arguments) });
} else {
if (arguments.sync) arguments.sync.call(arguments.sync.timer);
callback();
}
}
el.properties = {
// (time( ms ))
hide: function (time, sync) {
isRunning(el.hide, { time, sync }, () => {
is_running = "hide";
if (time) {
const intervalRate = time / 10;
el.style.opacity = 1;
const interval = setInterval(() => {
if (el.style.opacity > 0)
el.style.opacity = parseFloat(el.style.opacity) - 0.1;
else {
el.style.display = "none";
clearInterval(interval);
is_running = null;
queueFunc();
}
}, intervalRate);
} else {
el.style.display = "none";
is_running = null;
queueFunc();
}
});
},
// (displayType, time( ms ))
show: function (type, time, sync) {
isRunning(el.show, { type, time, sync }, () => {
is_running = "show";
if (time) {
const intervalRate = time / 10;
el.style.opacity = 0;
el.style.display = type ?? "block";
const interval = setInterval(() => {
if (el.style.opacity < 1)
el.style.opacity = parseFloat(el.style.opacity) + 0.1;
else {
el.style.display = type ?? "block";
clearInterval(interval);
is_running = null;
queueFunc();
}
}, intervalRate);
} else {
el.style.display = type ?? "block";
el.style.opacity = 1;
is_running = null;
queueFunc();
}
});
},
moveTo: function (dir, value, time, sync) {
isRunning(el.moveTo, { dir, value, time, sync }, () => {
is_running = "moveTo";
let direction = {
vector: null,
sign: null,
};
if (dir)
switch (dir) {
case "left":
direction = {
vector: "X",
sign: -1,
};
break;
case "right":
direction = {
vector: "X",
sign: 1,
};
break;
case "top":
direction = {
vector: "Y",
sign: -1,
};
break;
case "bottom":
direction = {
vector: "Y",
sign: 1,
};
break;
}
const matrix = new DOMMatrixReadOnly(el.style.transform);
let tX = matrix.m41;
let tY = matrix.m42;
if (time) {
const moveRate = value / time;
let gauging = 0;
const interval = setInterval(() => {
if (gauging <= value) {
el.style.transform = `translateX(${
direction.vector == "X" ? tX + direction.sign * gauging : tX
}px) translateY(${
direction.vector == "Y" ? tY + direction.sign * gauging : tY
}px)`;
gauging += moveRate * 10;
} else {
clearInterval(interval);
is_running = null;
queueFunc();
}
}, moveRate);
} else {
el.style.transform = `translateX(${
direction.vector == "X" ? tX + direction.sign * value : tX
}px) translateY(${
direction.vector == "Y" ? tY + direction.sign * value : tY
}px)`;
is_running = null;
queueFunc();
}
});
},
};
Object.keys(el.properties).map((__proto__) => {
el.__proto__[__proto__] = el.properties[__proto__];
});
delete el.properties;
return el;
}