<header>
<h2 class="title">Drag Events: Перетягування завдань</h2>
<p class="description">Демонстрація переміщення завдань між списками за допомогою Drag Events</p>
</header>
<main>
<div class="result">
<div class="tasks-container">
<h3>Завдання</h3>
<ul id="task-list">
<li class="task-item" draggable="true">Завдання 1</li>
<li class="task-item" draggable="true">Завдання 2</li>
<li class="task-item" draggable="true">Завдання 3</li>
</ul>
</div>
<div class="completed-container">
<h3>Завершено</h3>
<ul id="completed-list" class="drop-zone"></ul>
<button id="clear-completed">Очистити завершені</button>
</div>
</div>
</main>
body {
font-size: 16px;
line-height: 1.5;
font-family: monospace;
}
header {
background-color: #f1f1f1;
margin-bottom: 25px;
padding: 15px;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}
header h2.title {
padding-bottom: 15px;
border-bottom: 1px solid #999;
}
header p.description {
font-style: italic;
color: #222;
}
.result {
display: flex;
justify-content: space-around;
background-color: #f8f8f8;
padding: 15px;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}
.tasks-container, .completed-container {
width: 45%;
}
h3 {
text-align: center;
}
ul {
list-style: none;
padding: 0;
}
.task-item {
padding: 10px;
margin: 5px 0;
background-color: #e0e0e0;
cursor: grab;
border-radius: 4px;
}
.task-item.dragging {
opacity: 0.5;
}
.drop-zone {
min-height: 100px;
background-color: #f0f0f0;
border: 2px dashed #ccc;
border-radius: 4px;
padding: 10px;
}
button {
display: block;
margin: 10px auto;
padding: 8px 16px;
background-color: #007bff;
color: white;
border: none;
cursor: pointer;
border-radius: 4px;
}
document.querySelectorAll('.task-item').forEach(item => {
item.addEventListener('dragstart', (event) => {
event.target.classList.add('dragging');
event.dataTransfer.setData('text/plain', event.target.innerText);
});
item.addEventListener('dragend', (event) => {
event.target.classList.remove('dragging');
});
});
const completedList = document.getElementById('completed-list');
completedList.addEventListener('dragover', (event) => {
event.preventDefault();
});
completedList.addEventListener('drop', (event) => {
event.preventDefault();
const taskText = event.dataTransfer.getData('text/plain');
if (taskText) {
const newItem = document.createElement('li');
newItem.innerText = taskText;
newItem.classList.add('task-item');
completedList.appendChild(newItem);
}
});
document.getElementById('clear-completed').addEventListener('click', () => {
completedList.innerHTML = '';
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.