-
Notifications
You must be signed in to change notification settings - Fork 0
/
dragdrop.html
43 lines (36 loc) · 1.09 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
<!DOCTYPE HTML>
<html>
<head>
<style>
#div1, #div2, #div3
{float:left; width:200px; height:350px; margin:10px;padding:10px;border:1px solid #aaaaaa;}
#div1 {background-color:red}
#div2 {background-color:green}
#div3 {background-color:blue}
#div_drag {float:left; width:40px; height:20px; margin:5px;padding:5px;border:1px solid #aaaaaa;background-color:yellow}
</style>
<script>
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
</script>
</head>
<body>
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)">
<img src="img_w3slogo.gif" draggable="true" ondragstart="drag(event)" id="drag1" width="88" height="31">
</div>
<div id="div2" ondrop="drop(event)" ondragover="allowDrop(event)">
<div id="div_drag" draggable="true" ondragstart="drag(event)" id="drag2"></div>
</div>
<div id="div3" ondrop="drop(event)" ondragover="allowDrop(event)">
</div>
</body>
</html>