-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
42 lines (35 loc) · 1.06 KB
/
script.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
40
41
42
const dragAndDrop = () => {
const card = document.querySelector('.js-card');
const cells = document.querySelectorAll('.js-cell');
const dragStart = function () {
setTimeout(() => {
this.classList.add('hide')
}, 0)
};
const dragEnd = function () {
this.classList.remove('hide')
}
const dragOver = function (evt) {
evt.preventDefault();
}
const dragEnter = function (evt) {
evt.preventDefault();
this.classList.add('hovered');
}
const dragLeave = function () {
this.classList.remove('hovered');
}
const dragDrop = function () {
this.append(card)
this.classList.remove('hovered');
}
cells.forEach((cell) => {
cell.addEventListener('dragover', dragOver);
cell.addEventListener('dragenter', dragEnter);
cell.addEventListener('dragleave', dragLeave);
cell.addEventListener('drop', dragDrop)
})
card.addEventListener('dragstart', dragStart);
card.addEventListener('dragend', dragEnd);
};
dragAndDrop();