-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
53 lines (46 loc) · 1.21 KB
/
main.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
49
50
51
52
53
const targets = document.querySelectorAll('.target');
const toggles = document.querySelectorAll('.options input');
const options = {
capture: false,
once: false,
passive: false,
stopPropagation: false,
};
let targetCounter = 0;
function addFlash(e) {
targetCounter++;
if (options.stopPropagation) e.stopPropagation();
if (targetCounter == 3) {
setTimeout(() => this.classList.add('flash'), 600);
} else if (targetCounter == 2) {
setTimeout(() => this.classList.add('flash'), 300);
} else if (targetCounter == 1) {
this.classList.add('flash');
}
}
function addTargetListeners() {
targets.forEach(target => {
target.addEventListener('click', addFlash, options);
});
}
function removeTargetListeners() {
targets.forEach(target => {
target.removeEventListener('click', addFlash, options);
});
}
addTargetListeners();
targets.forEach(target => {
target.addEventListener('animationend', e => {
setTimeout(() => {
target.classList.remove('flash');
targetCounter = 0;
}, 1000);
});
});
toggles.forEach(toggle => {
toggle.addEventListener('click', e => {
removeTargetListeners();
options[e.target.value] = e.target.checked;
addTargetListeners();
});
});