-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdragDropCard.html
More file actions
65 lines (56 loc) · 1.65 KB
/
dragDropCard.html
File metadata and controls
65 lines (56 loc) · 1.65 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Drag and Drop</title>
<style>
.container {
display: flex;
}
.container-column {
width: 50%;
min-height: 200px;
border: 2px solid #ccc;
}
.item {
margin: 5px;
padding: 10px;
background-color: #f0f0f0;
border: 1px solid #999;
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<div id="left-container" class="container-column" ondrop="drop(event, 'left')" ondragover="allowDrop(event)"></div>
<div id="right-container" class="container-column" ondrop="drop(event, 'right')" ondragover="allowDrop(event)"></div>
</div>
<div id="item1" class="item" draggable="true" ondragstart="drag(event)">Item 1</div>
<div id="item2" class="item" draggable="true" ondragstart="drag(event)">Item 2</div>
<div id="item3" class="item" draggable="true" ondragstart="drag(event)">Item 3</div>
<script>
// Função para permitir soltar itens
function allowDrop(event) {
event.preventDefault();
}
// Função para arrastar o item
function drag(event) {
event.dataTransfer.setData("text", event.target.id);
}
// Função para soltar o item
function drop(event, destination) {
event.preventDefault();
var data = event.dataTransfer.getData("text");
var draggedItem = document.getElementById(data);
// Verifica o destino e move o item para a array correspondente
if (destination === 'left') {
document.getElementById("left-container").appendChild(draggedItem);
} else if (destination === 'right') {
document.getElementById("right-container").appendChild(draggedItem);
}
}
</script>
</body>
</html>