-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
50 lines (42 loc) · 1.26 KB
/
main.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
43
44
45
46
47
48
49
50
let btn = document.getElementById("btn");
let inp = document.getElementById("inp");
let boxs = document.querySelectorAll(".box");
let drag = null
btn.onclick = function(){
if(inp.value !=""){
boxs[0].innerHTML += `
<p class="item" draggable="true"">${inp.value}</p>
`
inp.value=""
}
dragItem();
}
function dragItem(){
let items = document.querySelectorAll(".item");
items.forEach(item=>{
item.addEventListener('dragstart', function(){
drag = item;
item.style.opacity="0.5"
});
item.addEventListener("dragend", function(){
console.log("Hello Word tow")
item.style.opacity ="1"
})
boxs.forEach(box=>{
box.addEventListener("dragover", function(e){
e.preventDefault()
this.style.background = "#090"
this.color = "#000"
});
box.addEventListener("dragleave", function(){
this.style.background = "#fff"
this.color = "#000"
});
box.addEventListener("drop", function(){
box.append(drag);
this.style.background = "#fff";
this.color = "#000";
});
});
});
}