-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdragAndDrop.html
62 lines (51 loc) · 1.7 KB
/
dragAndDrop.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
<!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 Image</title>
<style>
#dropZone {
width: 300px;
height: 300px;
border: 2px dashed #555;
display: flex;
align-items: center;
justify-content: center;
margin: 20px auto;
text-align: center;
}
.draggable {
width: 100px;
cursor: grab;
}
#dropZone img {
max-width: 100%;
max-height: 100%;
}
</style>
</head>
<body>
<h2 style="text-align: center;">Drag and Drop Example</h2>
<p style="text-align: center;">Drag the image below into the box.</p>
<div style="text-align: center;">
<img src="https://via.placeholder.com/100" id="dragImage" class="draggable" draggable="true" alt="Draggable">
</div>
<div id="dropZone">Drop Here</div>
<script>
// Simplified drag and drop logic
const dragImage = document.getElementById("dragImage");
const dropZone = document.getElementById("dropZone");
dragImage.ondragstart = (e) => e.dataTransfer.setData("id", e.target.id);
dropZone.ondragover = (e) => e.preventDefault();
dropZone.ondrop = (e) => {
e.preventDefault();
const draggedElement = document.getElementById(e.dataTransfer.getData("id"));
if (draggedElement) {
dropZone.innerHTML = ""; // Clear placeholder text
dropZone.appendChild(draggedElement); // Move the dragged element
}
};
</script>
</body>
</html>