day 21 completed

pull/109/head
couldntfindabetterusername 4 years ago
parent bc58937edc
commit eafca9af7d

@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>21 drag n drop</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="empty">
<div class="fill" draggable='true'></div>
</div>
<div class="empty"></div>
<div class="empty"></div>
<div class="empty"></div>
<div class="empty"></div>
<script src="script.js"></script>
</body>
</html>

@ -0,0 +1,39 @@
const fill = document.querySelector(".fill");
const empties = document.querySelectorAll(".empty");
fill.addEventListener("dragstart", dragStart);
fill.addEventListener("dragend", dragEnd);
for (const empty of empties) {
empty.addEventListener("dragover", dragOver);
empty.addEventListener("dragenter", dragEnter);
empty.addEventListener("dragleave", dragLeave);
empty.addEventListener("drop", dragDrop);
}
function dragStart() {
this.className += " hold";
setTimeout(() => (this.className = "invisible"), 0);
}
function dragEnd() {
this.className = "fill";
}
function dragOver(e) {
e.preventDefault();
}
function dragEnter(e) {
e.preventDefault();
this.className += " hovered";
}
function dragLeave() {
this.className = "empty";
}
function dragDrop() {
this.className = "empty";
this.append(fill);
}

@ -0,0 +1,43 @@
* {
margin: 0;
padding: 0;
}
body {
height: 100vh;
background-color: deepskyblue;
display: flex;
justify-content: center;
align-items: center;
}
.empty {
height: 150px;
width: 150px;
border: 3px solid black;
background-color: #fff;
margin: 10px;
}
.fill {
background-image: url("https://source.unsplash.com/random/150x150");
width: 150px;
height: 150px;
cursor: pointer;
}
.hold {
border: 5px solid #ccc;
}
.hovered {
background: #333;
border-color: white;
border-style: dashed;
}
@media screen and (max-width: 800px) {
body {
flex-direction: column;
}
}
Loading…
Cancel
Save