-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdragNdrop.html
116 lines (92 loc) · 2.63 KB
/
dragNdrop.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background: rgba(14, 13, 13);
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
overflow: hidden;
margin: 0;
}
.empty {
height: 200px;
width: 200px;
margin: 10px;
border: 3px solid white;
background: white;
}
.fill {
background: url(images/space/water-circle.jpg);
background-position: center;
background-size: cover;
height: 195px;
width: 195px;
cursor: pointer;
}
/* Javascript */
.hovered {
background: rgb(0, 255, 0);
border: 3px dashed white;
}
@media (max-width:800px) {
body {
flex-direction: column;
}
}
</style>
</head>
<body>
<div class="empty">
<div class="fill" draggable="true"></div>
</div>
<div class="empty"></div>
<div class="empty"></div>
<div class="empty"></div>
<div class="empty"></div>
<script>
const fill = document.querySelector(".fill"),
empties = document.querySelectorAll(".empty")
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)
}
function dragStart() {
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)
}
</script>
</body>
</html>