JSFiddle - React, Tailwind, and code Playground
by coryphoenixxx
HTML
<!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="styles.css">
<title>Drag & Drop</title>
</head>
<body>
<div>
<div class="row">
<div class="col-header start">Начать</div>
<div class="col-header progress">В процессе</div>
<div class="col-header done">Готовы</div>
</div>
<div class="row">
<div class="placeholder">
<div class="item" draggable="true">Перетащи меня</div>
</div>
<div class="placeholder"></div>
<div class="placeholder"></div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
CSS
@import url('https://fonts.googleapis.com/css?family=Roboto&display=swap');
* {
box-sizing: border-box;
}
body {
font-family: 'Roboto', sans-serif;
background-color: #e5e5e5;
display: flex;
padding-top: 5rem;
justify-content: center;
overflow: hidden;
margin: 0;
}
.row {
display: flex;
width: 600px;
justify-content: space-between;
margin-bottom: 1rem;
}
.col-header {
width: 150px;
box-shadow: 4px 4px 9px rgba(198, 198, 198, 0.36);
border-radius: 20px;
padding: 0.8rem 1rem;
color: #fff;
}
.item {
width: 150px;
height: 66px;
border: 1px solid #eee;
box-shadow: 4px 4px 9px rgba(198, 198, 198, 0.36);
border-radius: 20px;
background: #f7f6f7;
padding: 0.8rem 1rem;
color: #828282;
text-align: center;
cursor: grab;
}
.item:active {
cursor: grabbing;
}
.placeholder {
width: 150px;
height: 66px;
}
.start {
background: linear-gradient(90deg, #ff85e4 0%, #229efd 179.25%);
}
.progress {
background: linear-gradient(90deg, #209cff 0%, #68e0cf 100%);
}
.done {
background: linear-gradient(90deg, #84fab0 0%, #8fd3f4 100%);
}
.hold {
border: 5px solid #eee;
background-color: gold;
font-weight: bold;
}
.hide {
display: none;
}
.hovered {
border: 2px solid darkgray;
border-radius: 20px;
/*background-color: lightgray;*/
background-image: linear-gradient(45deg, #c4c9cc 25%, #dedede 25%, #dedede 50%, #c4c9cc 50%, #c4c9cc 75%, #dedede 75%, #dedede 100%);
background-size: 28px 28px;
}
JavaScript
const item = document.querySelector('.item')
const placeholders = document.querySelectorAll('.placeholder')
item.addEventListener('dragstart', dragstart)
item.addEventListener('dragend', dragend)
for(const placeholder of placeholders) {
placeholder.addEventListener('dragover', dragover)
placeholder.addEventListener('dragenter', dragenter)
placeholder.addEventListener('dragleave', dragleave)
placeholder.addEventListener('drop', dragdrop)
}
function dragstart(event) {
event.target.classList.add('hold')
setTimeout(() => event.target.classList.add('hide'), 0)
}
function dragend(event) {
event.target.className = 'item'
}
function dragover(event) {
event.preventDefault()
}
function dragenter(event) {
event.target.classList.add('hovered')
}
function dragleave(event) {
event.target.classList.remove('hovered')
}
function dragdrop(event) {
event.target.classList.remove('hovered')
event.target.append(item)
}