-
Notifications
You must be signed in to change notification settings - Fork 0
/
drag.html
61 lines (55 loc) · 1.39 KB
/
drag.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
<!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>
ul {
border: 1px solid;
padding: 30px;
}
li {
width: 100px;
height: 100px;
background-color: blanchedalmond;
}
</style>
</head>
<body>
<ul id="ul" draggable="">
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
<ul class="test">
</ul>
<script>
let dom = null;
const tar = document.getElementsByTagName('li')
Array.from(tar).forEach(ele => {
ele.setAttribute('draggable', true)
ele.ondragstart = function (params) {
dom = params.target
console.log(dom)
}
ele.ondragover = function (e) {
e.preventDefault();
}
ele.ondrop = function (params) {
console.log(ul)
ul.insertBefore(dom,params.target)
dom = null;
}
})
const test = document.getElementsByClassName('test')[0];
test.ondragover = function (e) {
e.preventDefault();
}
test.ondrop = function (params) {
console.log(params)
console.log(dom)
}
</script>
</body>
</html>