-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (34 loc) · 944 Bytes
/
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
40
41
42
const filled = document.querySelector('.filled')
const empties = document.querySelectorAll('.empty')
//Event listeners for fill;
filled.addEventListener('dragstart', dragStart)
filled.addEventListener('dragend', dragEnd)
//Drag functions for filled;
function dragStart(){
setTimeout(()=>(this.className = 'invisible'), 0)
}
function dragEnd(){
this.className = 'filled'
}
//Adding drag events to empties
for (const empty of empties){
empty.addEventListener('dragover', dragOver)
empty.addEventListener('dragenter', dragEnter)
empty.addEventListener('dragleave', dragLeave)
empty.addEventListener('drop', dragDrop)
}
//Drag functions for empties
function dragOver(e){
e.preventDefault()
}
function dragEnter(e){
e.preventDefault()
this.className += ' hovered'
}
function dragLeave(){
this.className = ' empty'
}
function dragDrop(){
this.append(filled)
this.className = 'empty'
}