-
Notifications
You must be signed in to change notification settings - Fork 14
/
043.图片拖拽另一个盒子中.html
53 lines (47 loc) · 1.39 KB
/
043.图片拖拽另一个盒子中.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./assets/global.css">
<style>
.from,
.to,
.move {
display: inline-block;
width: 200px;
height: 300px;
border: 1px dashed red;
}
</style>
</head>
<body>
<div class="from">
<img class="move" src="./assets/movie-poster/m-byxz.jpg" draggable="true">
</div>
<div class="to">
</div>
<script type="module">
var from = document.querySelector(".from");
var to = document.querySelector(".to");
var move = document.querySelector(".move");
// drag:拖, over:经过, 就是红盒子拖拽到它身上时会调用
// 默认是不接受,如果要想让它接收,需要禁用默认事件
to.ondragover = function (target) {
target.preventDefault();
}
//drop: 放下, 松手
to.ondrop = function () {
to.appendChild(move);
}
from.ondragover = function (target) {
target.preventDefault();
}
//drop: 放下, 松手
from.ondrop = function () {
from.appendChild(move);
}
</script>
</body>
</html>