-
Notifications
You must be signed in to change notification settings - Fork 0
/
dragdrop.html
85 lines (79 loc) · 2.19 KB
/
dragdrop.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
<!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;
}
.container{
background-color: #0b0423;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100vh;
}
#left, #right{
width: 300px;
min-height: 400px;
border: 2px #fff dashed;
padding: 12px;
margin: 20px;
}
.list{
background: #e91e63;
height: 60px;
margin: 30px;
color: #fff;
display: flex;
align-items: center;
font-size: 18px;
cursor: grab;
}
.list img{
width: 40px;
}
</style>
</head>
<body>
<div class="container">
<div id="left">
<div class="list" draggable="true"><img src="https://cdn4.iconfinder.com/data/icons/android-11/512/three_dots-256.png">list 1</div>
<div class="list" draggable="true"><img src="https://cdn4.iconfinder.com/data/icons/android-11/512/three_dots-256.png">list 2</div>
<div class="list" draggable="true"><img src="https://cdn4.iconfinder.com/data/icons/android-11/512/three_dots-256.png">list 3</div>
<div class="list" draggable="true"><img src="https://cdn4.iconfinder.com/data/icons/android-11/512/three_dots-256.png">list 4</div>
</div>
<div id="right"></div>
</div>
</div>
<script>
let lists = document.querySelectorAll(".list");
let right = document.getElementById("right");
let left = document.getElementById("left");
for(list of lists){
list.addEventListener("dragstart", function(e){
let selected = e.target;
right.addEventListener("dragover", function(e){
e.preventDefault();
});
right.addEventListener("drop", function(e){
right.appendChild(selected);
selected = null;
});
left.addEventListener("dragover", function(e){
e.preventDefault();
});
left.addEventListener("drop", function(e){
left.appendChild(selected);
selected = null;
});
});
}
</script>
</body>
</html>