-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (31 loc) · 1.01 KB
/
index.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
38
39
const item = document.querySelector('.object');
const placeholders = document.querySelectorAll('.placeholder');
item.addEventListener('dragstart', dragStart);
item.addEventListener('dragend', dragEnd);
placeholders.forEach(placeholder => {
placeholder.addEventListener('dragover', dragOver);
placeholder.addEventListener('dragenter', dragEnter);
placeholder.addEventListener('dragleave', dragLeave);
placeholder.addEventListener('drop', dragDrop);
})
function dragStart(event) {
event.target.classList.add('hold');
setTimeout( () => event.target.classList.add('hide'), 0);
}
function dragEnd(event) {
event.target.classList.remove('hold');
event.target.classList.remove('hide');
}
function dragOver(event) {
event.preventDefault();
}
function dragEnter(event) {
event.target.classList.add('hovered');
}
function dragLeave(event) {
event.target.classList.remove('hovered');
}
function dragDrop(event) {
event.target.append(item);
event.target.classList.remove('hovered');
}