-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy path12-api-dnd.html
64 lines (37 loc) · 1.23 KB
/
12-api-dnd.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>API drag and drop</title>
<link rel="stylesheet" href="./bootstrap.min.css">
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
function allowDrop(ev) {
// potlac vychozi chovani browseru, ktere neumoznuje pustit pretahovany obrazek
// pak se na kosiku bude ukazovat plus, ktere uzivateli napovida, ze tady muze obrazek pustit
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
document.getElementById('kosik').style.border='3px dashed red';
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
document.getElementById('kosik').style.border='3px solid dodgerblue';
}
</script>
</head>
<body>
<div class="container">
<h1>API drag and drop</h1>
<img src="img/hd-small.jpg" width="221" height="176" alt="HD Road King" draggable="true"
ondragstart="drag(event)" id="motorka">
<br>
<br>
<div id='kosik' style="width: 227px; height: 182px; border: 3px solid dodgerblue;" ondragover="allowDrop(event)" ondrop="drop(event)">
</div>
</div>
</body>
</html>