-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
29 lines (22 loc) · 692 Bytes
/
Copy pathscript.js
File metadata and controls
29 lines (22 loc) · 692 Bytes
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
let draggedCard = null;
function drag(event) {
draggedCard = event.target;
event.dataTransfer.effectAllowed = "move";
event.dataTransfer.setData("text/plain", "card");
}
function dragoverHandler(event) {
event.preventDefault();
event.dataTransfer.dropEffect = "move";
}
function dropHandler(event) {
event.preventDefault();
const targetList = event.currentTarget;
const targetCard = event.target.closest(".card");
if (!draggedCard || !draggedCard.classList.contains("card")) return;
if (targetCard && targetCard !== draggedCard) {
targetList.insertBefore(draggedCard, targetCard);
} else {
targetList.appendChild(draggedCard);
}
draggedCard = null;
}