Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2479f79

Browse files
committed
Project #10 Added - Create Todo App (Drag & Drop)
1 parente137cd7 commit2479f79

File tree

3 files changed

+319
-0
lines changed

3 files changed

+319
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!DOCTYPE html>
2+
<htmllang="en">
3+
<head>
4+
<metacharset="UTF-8"/>
5+
<metaname="viewport"content="width=device-width, initial-scale=1.0"/>
6+
<linkrel="stylesheet"href="style.css"/>
7+
<title>Draggable Todo App</title>
8+
</head>
9+
<body>
10+
<!-- modal -->
11+
<divclass="modal"id="todo_form">
12+
<divclass="header">
13+
<divclass="title">Add Todo</div>
14+
<buttonclass="btn close-modal">&times;</button>
15+
</div>
16+
<divclass="body">
17+
<inputtype="text"id="todo_input"/>
18+
<inputtype="submit"value="Add Todo"id="todo_submit"/>
19+
</div>
20+
</div>
21+
<!-- todo -->
22+
<divclass="todo-container">
23+
<divclass="status"id="no_status">
24+
<h1>No Status</h1>
25+
<buttonid="add_btn"data-target-modal="#todo_form">+ Add Todo</button>
26+
<divclass="todo"draggable="true">
27+
Buy a Pizza
28+
<spanclass="close">&times;</span>
29+
</div>
30+
</div>
31+
<divclass="status">
32+
<h1>Not Started</h1>
33+
</div>
34+
<divclass="status">
35+
<h1>In Progress</h1>
36+
</div>
37+
<divclass="status">
38+
<h1>Completed</h1>
39+
</div>
40+
</div>
41+
42+
<divid="overlay"></div>
43+
44+
<scriptsrc="script.js"></script>
45+
</body>
46+
</html>
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
consttodos=document.querySelectorAll(".todo");
2+
constall_status=document.querySelectorAll(".status");
3+
letdraggableTodo=null;
4+
5+
todos.forEach((todo)=>{
6+
todo.addEventListener("dragstart",dragStart);
7+
todo.addEventListener("dragend",dragEnd);
8+
});
9+
10+
functiondragStart(){
11+
draggableTodo=this;
12+
setTimeout(()=>{
13+
this.style.display="none";
14+
},0);
15+
console.log("dragStart");
16+
}
17+
18+
functiondragEnd(){
19+
draggableTodo=null;
20+
setTimeout(()=>{
21+
this.style.display="block";
22+
},0);
23+
console.log("dragEnd");
24+
}
25+
26+
all_status.forEach((status)=>{
27+
status.addEventListener("dragover",dragOver);
28+
status.addEventListener("dragenter",dragEnter);
29+
status.addEventListener("dragleave",dragLeave);
30+
status.addEventListener("drop",dragDrop);
31+
});
32+
33+
functiondragOver(e){
34+
e.preventDefault();
35+
// console.log("dragOver");
36+
}
37+
38+
functiondragEnter(){
39+
this.style.border="1px dashed #ccc";
40+
console.log("dragEnter");
41+
}
42+
43+
functiondragLeave(){
44+
this.style.border="none";
45+
console.log("dragLeave");
46+
}
47+
48+
functiondragDrop(){
49+
this.style.border="none";
50+
this.appendChild(draggableTodo);
51+
console.log("dropped");
52+
}
53+
54+
/* modal */
55+
constbtns=document.querySelectorAll("[data-target-modal]");
56+
constclose_modals=document.querySelectorAll(".close-modal");
57+
constoverlay=document.getElementById("overlay");
58+
59+
btns.forEach((btn)=>{
60+
btn.addEventListener("click",()=>{
61+
document.querySelector(btn.dataset.targetModal).classList.add("active");
62+
overlay.classList.add("active");
63+
});
64+
});
65+
66+
close_modals.forEach((btn)=>{
67+
btn.addEventListener("click",()=>{
68+
constmodal=btn.closest(".modal");
69+
modal.classList.remove("active");
70+
overlay.classList.remove("active");
71+
});
72+
});
73+
74+
window.onclick=(event)=>{
75+
if(event.target==overlay){
76+
constmodals=document.querySelectorAll(".modal");
77+
modals.forEach((modal)=>modal.classList.remove("active"));
78+
overlay.classList.remove("active");
79+
}
80+
};
81+
82+
/* create todo */
83+
consttodo_submit=document.getElementById("todo_submit");
84+
85+
todo_submit.addEventListener("click",createTodo);
86+
87+
functioncreateTodo(){
88+
consttodo_div=document.createElement("div");
89+
constinput_val=document.getElementById("todo_input").value;
90+
consttxt=document.createTextNode(input_val);
91+
92+
todo_div.appendChild(txt);
93+
todo_div.classList.add("todo");
94+
todo_div.setAttribute("draggable","true");
95+
96+
/* create span */
97+
constspan=document.createElement("span");
98+
constspan_txt=document.createTextNode("\u00D7");
99+
span.classList.add("close");
100+
span.appendChild(span_txt);
101+
102+
todo_div.appendChild(span);
103+
104+
no_status.appendChild(todo_div);
105+
106+
span.addEventListener("click",()=>{
107+
span.parentElement.style.display="none";
108+
});
109+
// console.log(todo_div);
110+
111+
todo_div.addEventListener("dragstart",dragStart);
112+
todo_div.addEventListener("dragend",dragEnd);
113+
114+
document.getElementById("todo_input").value="";
115+
todo_form.classList.remove("active");
116+
overlay.classList.remove("active");
117+
}
118+
119+
constclose_btns=document.querySelectorAll(".close");
120+
121+
close_btns.forEach((btn)=>{
122+
btn.addEventListener("click",()=>{
123+
btn.parentElement.style.display="none";
124+
});
125+
});
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
* {
2+
box-sizing: border-box;
3+
}
4+
5+
body {
6+
font-family:"Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
7+
min-height:100vh;
8+
display: flex;
9+
justify-content: center;
10+
align-items: center;
11+
}
12+
13+
.todo-container {
14+
width:1000px;
15+
height:80vh;
16+
display: flex;
17+
}
18+
19+
.status {
20+
width:25%;
21+
background-color:#f3f3f3;
22+
position: relative;
23+
padding:60px1rem0.5rem;
24+
}
25+
26+
.status:nth-child(even) {
27+
background-color:#e9e9e96b;
28+
}
29+
30+
.statush1 {
31+
position: absolute;
32+
top:0;
33+
left:0;
34+
background-color:#343434;
35+
color:#f3f3f3;
36+
margin:0;
37+
width:100%;
38+
padding:0.5rem1rem;
39+
}
40+
41+
#add_btn {
42+
padding:0.5rem1rem;
43+
background-color:#ccc;
44+
outline: none;
45+
border: none;
46+
width:100%;
47+
font-size:1.5rem;
48+
margin:0.5rem0;
49+
border-radius:4px;
50+
cursor: pointer;
51+
}
52+
53+
#add_btn:hover {
54+
background-color:#aaa;
55+
}
56+
57+
.todo {
58+
display: flex;
59+
justify-content: space-between;
60+
align-items: center;
61+
position: relative;
62+
background-color:#fff;
63+
box-shadow:rgba(15,15,15,0.1)0px0px0px1px,
64+
rgba(15,15,15,0.1)0px2px4px;
65+
border-radius:4px;
66+
padding:0.5rem1rem;
67+
font-size:1.5rem;
68+
margin:0.5rem0;
69+
}
70+
71+
.todo .close {
72+
position: absolute;
73+
right:1rem;
74+
top:0rem;
75+
font-size:2rem;
76+
color:#ccc;
77+
cursor: pointer;
78+
}
79+
80+
.todo .close:hover {
81+
color:#343444;
82+
}
83+
84+
/* modal */
85+
86+
.close-modal {
87+
background: none;
88+
border: none;
89+
font-size:1.5rem;
90+
}
91+
92+
.modal {
93+
width:450px;
94+
position: fixed;
95+
top:-50%;
96+
left:50%;
97+
transform:translate(-50%,-50%);
98+
transition: top0.3s ease-in-out;
99+
border:1px solid#ccc;
100+
border-radius:10px;
101+
z-index:2;
102+
background-color:#fff;
103+
}
104+
105+
.modal.active {
106+
top:15%;
107+
}
108+
109+
.modal .header {
110+
display: flex;
111+
justify-content: space-between;
112+
align-items: center;
113+
border-bottom:1px solid#ccc;
114+
padding:0.5rem;
115+
background-color:rgba(0,0,0,0.05);
116+
}
117+
118+
.modal .body {
119+
padding:0.75rem;
120+
}
121+
122+
#overlay {
123+
display: none;
124+
position: fixed;
125+
top:0;
126+
left:0;
127+
width:100%;
128+
height:100%;
129+
background-color:rgba(0,0,0,0.3);
130+
}
131+
132+
#overlay.active {
133+
display: block;
134+
}
135+
136+
#todo_input,
137+
#todo_submit {
138+
padding:0.5rem1rem;
139+
width:100%;
140+
margin:0.25rem;
141+
}
142+
143+
#todo_submit {
144+
background-color:#4caf50;
145+
color:#f3f3f3;
146+
font-size:1.25rem;
147+
border: none;
148+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp