Drag n drop

This commit is contained in:
Brad Traversy 2020-11-23 12:00:08 -05:00
parent d29ac3e28f
commit e3ea569cb6
6 changed files with 103 additions and 148 deletions

20
drag-n-drop/index.html Normal file
View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<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="script.js"></script>
</body>
</html>

39
drag-n-drop/script.js Normal file
View File

@ -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)
}

44
drag-n-drop/style.css Normal file
View File

@ -0,0 +1,44 @@
* {
box-sizing: border-box;
}
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: 145px;
width: 145px;
cursor: pointer;
}
.hold {
border: solid 5px #ccc;
}
.hovered {
background-color: #333;
border-color: white;
border-style: dashed;
}
@media (max-width: 800px) {
body {
flex-direction: column;
}
}

View File

@ -1,39 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA==" crossorigin="anonymous" />
<link rel="stylesheet" href="style.css" />
<title>Social Links</title>
</head>
<body>
<div class="container a b c" id="container">
<button id="open" class="open-btn">
<i class="fas fa-share-alt"></i>
</button>
<a href="https://youtube.com" class="ytb" target="_blank">
<i class="fab fa-youtube"></i>
</a>
<a href="https://twitter.com" class="twt" target="_blank">
<i class="fab fa-twitter"></i>
</a>
<a href="#" class="x" id="close">
<i class="fas fa-times"></i>
</a>
<a href="https://linkedin.com" class="lin" target="_blank">
<i class="fab fa-linkedin"></i>
</a>
<a href="https://instagram.com" class="ins" target="_blank">
<i class="fab fa-instagram"></i>
</a>
</div>
<script src="script.js"></script>
</body>
</html>

View File

@ -1,7 +0,0 @@
const container = document.getElementById('container')
const open = document.getElementById('open')
const close = document.getElementById('close')
open.addEventListener('click', () => container.classList.add('open'))
close.addEventListener('click', () => container.classList.remove('open'))

View File

@ -1,102 +0,0 @@
@import url('https://fonts.googleapis.com/css?family=Muli&display=swap');
* {
box-sizing: border-box;
}
body {
background-color: #e0e0e0;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
}
.container {
background-color: #fff;
border-radius: 50px;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
position: relative;
transition: 0.4s ease;
height: 70px;
width: 70px;
}
.container.open {
width: 350px;
}
.container .open-btn {
position: absolute;
top: 0;
left: 0;
background-image: linear-gradient(
110.1deg,
rgba(241, 115, 30, 1) 18.9%,
rgba(231, 29, 54, 1) 90.7%
);
color: #fff;
cursor: pointer;
border: 0;
border-radius: 50%;
font-size: 26px;
display: flex;
align-items: center;
justify-content: center;
padding: 0;
height: 70px;
width: 70px;
z-index: 100;
}
.container.open .open-btn {
display: none;
}
.container a {
background-color: #fff;
border-radius: 50%;
font-size: 26px;
display: flex;
align-items: center;
justify-content: center;
position: absolute;
top: 0;
left: 0;
margin: 10px;
height: 50px;
width: 50px;
text-decoration: none;
opacity: 0;
}
.container.open a {
position: static;
opacity: 1;
transition: 0.4s ease;
}
.container a.ytb {
background-color: #ff0000;
}
.container a.twt {
background-color: #1da1f2;
}
.container a.x {
background-color: #282c37;
}
.container a.lin {
background-color: #007bb5;
}
.container a.ins {
background-color: #c32aa3;
}
.container a i {
color: #fff;
}