-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
44 lines (32 loc) · 1010 Bytes
/
app.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
const item = document.querySelector(".item")
const placeholders = document.querySelectorAll(".placeholder")
item.addEventListener("dragstart",dragstart)
item.addEventListener("dragend",dragend)
for (const placeholder of placeholders) {
placeholder.addEventListener("dragover",dragover)
placeholder.addEventListener("dragenter",dragenter)
placeholder.addEventListener("dragleave",dragleave)
placeholder.addEventListener("drop",dragdrop)
}
function dragstart(event) {
event.target.classList.add("hold")
setTimeout(() => event.target.classList.add
("hide"), 0)
}
function dragend(event) {
event.target.className = "item"
}
function dragover(event) {
event.preventDefault()
}
function dragenter(event) {
event.target.classList.add("hovered")
console.log("drag enter")
}
function dragleave(event) {
event.target.classList.remove("hovered")
}
function dragdrop(event) {
event.target.classList.remove("hovered")
event.target.append(item)
}