Web-based Kanban Board JavaScript, HTML, CSS
👤 Sharing: AI
```javascript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kanban Board</title>
<style>
body {
font-family: sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}
.kanban-container {
display: flex;
justify-content: space-around;
padding: 20px;
}
.kanban-column {
background-color: #eee;
width: 250px;
min-height: 300px;
padding: 10px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
flex: 1; /* Allows columns to share available space */
margin: 0 10px; /* Adds spacing between columns */
}
.kanban-column:first-child {
margin-left: 0;
}
.kanban-column:last-child {
margin-right: 0;
}
.kanban-column h2 {
margin-top: 0;
text-align: center;
font-size: 1.2em;
margin-bottom: 10px;
}
.kanban-card {
background-color: #fff;
padding: 10px;
margin-bottom: 10px;
border-radius: 5px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
cursor: grab;
}
.kanban-card:active {
cursor: grabbing;
}
.add-button {
display: block;
width: 100%;
padding: 8px;
margin-top: 10px;
border: none;
background-color: #4CAF50;
color: white;
border-radius: 5px;
cursor: pointer;
text-align: center;
text-decoration: none;
font-size: 1em;
}
.add-button:hover {
background-color: #3e8e41;
}
/* Modal Styles */
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0, 0, 0, 0.4);
}
.modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
max-width: 500px;
border-radius: 5px;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
cursor: pointer;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
#new-task-description {
width: 100%;
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box; /* Important: Makes padding part of the width */
}
.save-task-button {
background-color: #4CAF50;
color: white;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
}
.save-task-button:hover {
background-color: #3e8e41;
}
</style>
</head>
<body>
<div class="kanban-container">
<div class="kanban-column" id="todo">
<h2>To Do</h2>
<a href="#" class="add-button" data-column="todo" onclick="openModal('todo')">Add Task</a>
</div>
<div class="kanban-column" id="in-progress">
<h2>In Progress</h2>
<a href="#" class="add-button" data-column="in-progress" onclick="openModal('in-progress')">Add Task</a>
</div>
<div class="kanban-column" id="done">
<h2>Done</h2>
<a href="#" class="add-button" data-column="done" onclick="openModal('done')">Add Task</a>
</div>
</div>
<!-- The Modal -->
<div id="myModal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeModal()">×</span>
<h2>Add New Task</h2>
<label for="new-task-description">Task Description:</label>
<textarea id="new-task-description" rows="4" cols="50"></textarea>
<button class="save-task-button" onclick="saveNewTask()">Save Task</button>
</div>
</div>
<script>
let currentColumn = null; // Store the column to which the task should be added
function allowDrop(event) {
event.preventDefault();
}
function drag(event) {
event.dataTransfer.setData("text", event.target.id);
}
function drop(event) {
event.preventDefault();
const data = event.dataTransfer.getData("text");
const draggedElement = document.getElementById(data);
const dropzone = event.target;
// Ensure the dropzone is a kanban-column
if (dropzone.classList.contains('kanban-column')) {
dropzone.appendChild(draggedElement);
} else if (dropzone.parentNode.classList.contains('kanban-column')) {
dropzone.parentNode.appendChild(draggedElement);
}
}
function openModal(columnId) {
currentColumn = columnId;
document.getElementById("myModal").style.display = "block";
}
function closeModal() {
document.getElementById("myModal").style.display = "none";
document.getElementById("new-task-description").value = ""; // Clear the textarea
}
function saveNewTask() {
const taskDescription = document.getElementById("new-task-description").value;
if (taskDescription.trim() !== "") {
const newTask = createTaskCard(taskDescription);
document.getElementById(currentColumn).appendChild(newTask);
closeModal(); // Close the modal after saving
} else {
alert("Please enter a task description.");
}
}
function createTaskCard(description) {
const card = document.createElement("div");
card.classList.add("kanban-card");
card.textContent = description;
card.id = "task-" + Date.now(); // Unique ID for drag/drop
card.draggable = true;
card.setAttribute("ondragstart", "drag(event)");
return card;
}
// Close the modal if the user clicks outside of it
window.onclick = function(event) {
const modal = document.getElementById("myModal");
if (event.target == modal) {
closeModal();
}
}
// Make columns droppable
const columns = document.querySelectorAll('.kanban-column');
columns.forEach(column => {
column.setAttribute("ondrop", "drop(event)");
column.setAttribute("ondragover", "allowDrop(event)");
});
</script>
</body>
</html>
```
👁️ Viewed: 9
Comments