-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
37 lines (32 loc) · 1017 Bytes
/
app.js
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
const item = document.querySelector('.item');
const placeholders = document.querySelectorAll('.placeholder');
const dragover = (event) => {
event.preventDefault();
};
const dragenter = (event) => {
event.target.classList.add('hovered');
};
const dragleave = (event) => {
event.target.classList.remove('hovered');
};
const dragdrop = (event) => {
event.target.classList.remove('hovered');
event.target.appendChild(item);
};
for (const placeholder of placeholders) {
placeholder.addEventListener('dragover', dragover);
placeholder.addEventListener('dragenter', dragenter);
placeholder.addEventListener('dragleave', dragleave);
placeholder.addEventListener('drop', dragdrop);
}
const dragStart = (event) => {
event.target.classList.add('dragged');
setTimeout(() => {
event.target.classList.add('hide');
}, 0);
};
const dragEnd = (event) => {
event.target.classList.remove('dragged', 'hide');
};
item.addEventListener('dragstart', dragStart);
item.addEventListener('dragend', dragEnd);