-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Block Element and Variables... | ||
|
||
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); | ||
} | ||
|
||
// Functions... | ||
|
||
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(e) { | ||
this.className = "empty"; | ||
} | ||
|
||
function dragDrop(e) { | ||
this.className = "empty"; | ||
this.append(fill); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!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" /> | ||
<link rel="stylesheet" href="./style.css" /> | ||
<title>Drag N Drop</title> | ||
</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="./app.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
*::after, | ||
*::before { | ||
box-sizing: border-box; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
body { | ||
background-color: steelblue; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
height: 100vh; | ||
overflow: hidden; | ||
margin: 0; | ||
} | ||
|
||
.empty { | ||
height: 150px; | ||
width: 150px; | ||
margin: 10px; | ||
border: solid 3px black; | ||
background: white; | ||
} | ||
|
||
.fill { | ||
background-image: url("https://source.unsplash.com/random/150x150"); | ||
height: 150px; | ||
width: 150px; | ||
cursor: pointer; | ||
} | ||
|
||
.hold { | ||
border: solid 5px #ccc; | ||
} | ||
|
||
.hovered { | ||
background-color: #333; | ||
border-color: #fff; | ||
border-style: dashed; | ||
} | ||
|
||
@media (max-width: 800px) { | ||
body { | ||
flex-direction: column; | ||
} | ||
} |