-
-
Notifications
You must be signed in to change notification settings - Fork 524
/
script.js
40 lines (32 loc) · 981 Bytes
/
script.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
const fill = document.querySelector(".fill");
const empties = document.querySelectorAll(".empty");
const dragStart = function () {
this.className += " hold";
setTimeout(() => (this.className = "invisible"), 0);
};
const dragEnd = function () {
this.className = "fill";
};
const dragOver = function (e) {
// Ref: https://developer.cdn.mozilla.net/en-US/docs/Web/API/Document/dragover_event
e.preventDefault();
};
const dragEnter = function (e) {
e.preventDefault();
this.className += " hovered";
};
const dragLeave = function () {
this.className = "empty";
};
const dragDrop = function () {
this.className = "empty";
this.append(fill);
};
fill.addEventListener("dragstart", dragStart);
fill.addEventListener("dragend", dragEnd);
for (const empty of empties) {
empty.addEventListener("dragover", dragOver);
empty.addEventListener("dragenter", dragEnter);
empty.addEventListener("dragleave", dragLeave);
empty.addEventListener("drop", dragDrop);
}