-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (31 loc) · 856 Bytes
/
script.js
File metadata and controls
39 lines (31 loc) · 856 Bytes
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
const fill = document.querySelector(`.fill`);
const empties = document.querySelectorAll(`.empty`);
function dragStart() {
this.className += ' hold';
setTimeout(() => this.className = 'invisible', 0);
}
function dragEnd() {
this.className = 'fill';
}
function dragOver(e) {
e.preventDefault();
}
function dragEnter(e) {
e.preventDefault();
this.className += ' hovered';
}
function dragLeave() {
this.className = 'empty';
}
function dragDrop() {
this.className = 'empty';
this.append(fill);
}
fill.addEventListener('dragstart', dragStart);
fill.addEventListener('dragend', dragEnd);
empties.forEach((empty) => {
empty.addEventListener('dragover', dragOver);
empty.addEventListener('dragenter', dragEnter);
empty.addEventListener('dragleave', dragLeave);
empty.addEventListener('drop', dragDrop);
})