-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[1주차] 신동현 미션 제출합니다 #9
base: master
Are you sure you want to change the base?
Changes from 1 commit
f9d344d
eed56d2
7786bda
877d2e2
89faf89
7e12519
5889c51
9352968
43a6a30
d36548e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,20 +9,25 @@ | |
|
||
<body> | ||
<div class="container"> | ||
<div class = "header"> | ||
<div class = "round Red" ></div> | ||
<div class = "round Yellow" ></div> | ||
<div class = "round Green " ></div> | ||
</div> | ||
<h1>Todo List</h1> | ||
<div class ="todo_input"> | ||
<div class ="todoInput"> | ||
<input type = "text" id="inputTodo" placeholder="📍 Enter your to-do"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 엔터를 쳤을 때, todolist에 반영이 안되어서 해당 input의 placeholder 텍스트를 바꾸어도 좋을 것 같아요! |
||
<button> + </button> | ||
<button class ="addBtn"> + </button> | ||
</div> | ||
|
||
<div class = "todoContainer"> | ||
<h2>List To Do</h2> | ||
<div id = "todoList">과제</div> | ||
<div id = "todoList"></div> | ||
</div> | ||
|
||
<div class = "doneContainer"> | ||
<h2>List Done</h2> | ||
<div id = "doneList">수강신청</div> | ||
<div id = "doneList"></div> | ||
</div> | ||
|
||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const inputTodo = document.querySelector("#inputTodo"); | ||
const todoItems = document.querySelector("#todoList"); | ||
const doneList = document.querySelector("#doneList"); | ||
const doneArray = document.querySelectorAll("#doneList .todoItem"); | ||
const addBtn = document.querySelector(".addBtn"); | ||
const todoTextArray = []; | ||
const doneTextArray = []; | ||
|
||
function createBtn(className, text) { | ||
var button = document.createElement("div"); | ||
|
||
button.textContent = text; | ||
button.setAttribute("class", "listBtns"); | ||
button.classList.add(className); | ||
return button; | ||
} | ||
|
||
function deleteItem() { | ||
var removeBtns = document.querySelectorAll(".deleteBtn"); | ||
for (i = 0; i < removeBtns.length; i++) { | ||
removeBtns[i].addEventListener("click", function () { | ||
if (this.parentNode) | ||
this.parentNode.parentNode.removeChild(this.parentNode); | ||
}); | ||
} | ||
} | ||
|
||
function todoToDone() { | ||
var doneBtns = document.querySelectorAll(".doneBtn"); | ||
|
||
for (var i = 0; i < doneBtns.length; i++) { | ||
doneBtns[i].addEventListener("click", function () { | ||
if (this.parentNode.parentNode) | ||
doneList.insertBefore(this.parentNode, doneList.childNodes[0]); | ||
}); | ||
} | ||
} | ||
|
||
function newTodo() { | ||
var newDiv = document.createElement("div"); | ||
var newText = document.createTextNode(inputTodo.value); // input 태그에 쓴 text 값 | ||
newDiv.appendChild(newText); | ||
var doneBtn = createBtn("doneBtn", "✅"); | ||
var deleteBtn = createBtn("deleteBtn", "❌"); | ||
newDiv.appendChild(doneBtn); | ||
newDiv.appendChild(deleteBtn); | ||
newDiv.setAttribute("class", "todoItem"); | ||
|
||
todoItems.insertBefore(newDiv, todoItems.childNodes[0]); | ||
inputTodo.value = ""; | ||
//deleteBtn 누르면 삭제 구현 | ||
deleteItem(); | ||
|
||
//doneBtn 누르면 todo -> done으로 | ||
todoToDone(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 현재 플로우가, 새로운 아이템을 추가하는 순간에 delete 버튼과 done 버튼에 event handler를 전달해주는 방식을 사용하신 것 같아요! 좋은 방법이긴 한데, 현재 deleteItem 함수와 todoToDone 함수에서는 지금 당장 추가하려는 항목의 버튼에만 event handler를 할당하는게 아니라, 각각의 class를 가진 모든 항목에 event handler를 할당고 있는 것 같아요, 그렇게 되면 각각의 버튼들에 event handler들이 쌓이게 되는 것 같아요! |
||
} | ||
|
||
function init() { | ||
addBtn.addEventListener("click", newTodo); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분은 form 태그를 사용하는 걸로 해결해볼 수 있을 것 같아요 😄 |
||
} | ||
|
||
init(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,14 +7,46 @@ body{ | |
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
|
||
.container{ | ||
background-color: white; | ||
width: 300px; | ||
height: 600px; | ||
height: 650px; | ||
border-radius: 10px; | ||
} | ||
.todoContainer, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 스타일을 위해서 이상적인 높이를 지정하는 것은 좋은 것이라고 생각해요~~
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 컨테이너 내용이 넘치는 부분은 생각하지 못했는데,, 꼼꼼한 코드리뷰 감사합니다.. 🙇♀️ 대균님 덕분에 좋은 정보 많이 얻고 많이 배웠어요!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CSS 단위 설정하실 때 픽셀(px) 단위가 아닌 rem, em 등을 사용해보시는 것도 좋을 것 같아요. REM이 반응형 디자인에서 유용하게 사용된다고 하더라구요! 저도 px 쓰는게 익숙한데 최대한 rem 써보려고 노력 중입니다🥲 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 앞으로 REM 에 익숙해지도록 해야겠어요 :) 링크 감사합니당!!ㅎㅎ |
||
.doneContainer { | ||
flex: 1; | ||
padding: 10px; | ||
background-color: #f0f0f0; | ||
margin: 10px; | ||
height: 200px; | ||
} | ||
.header{ | ||
height: 15px; | ||
width:100%; | ||
display:flex; | ||
} | ||
.round{ | ||
width: 10px; | ||
height: 10px; | ||
border-radius: 50%; | ||
margin:5px; | ||
} | ||
.round:hover{ | ||
cursor: pointer; | ||
} | ||
.Red { | ||
background-color: #F5655B; | ||
} | ||
|
||
.round.Yellow { | ||
background-color: #F6BD3B; | ||
} | ||
|
||
.Green { | ||
background-color: #43C645; | ||
} | ||
|
||
.todo_input{ | ||
width:100%; | ||
background-color: whitesmoke; | ||
|
@@ -34,4 +66,17 @@ body{ | |
padding-left: 10px; | ||
background-color: rgb(233, 233, 233); | ||
|
||
} | ||
.deleteBtn{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이건 스타일적인 부분이긴 한데, 만약 todo에 긴 문자열이 들어가게 되면, done, delete 버튼과 겹치게 되는데, 해당 버튼들을 absolute로 위치를 지정해주어서 그런 것 같아요! 만약, absolute로 지정하고 싶으면 그 옆에 있는 element에 최대 width를 설정해 주어서 겹치지 않게 하거나, 아니면 todoItem에 flex box를 적용했으니 absolute 말고 그냥 일반적으로 나열시키는 것도 좋을 것 같아요!
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아 버튼을 오른쪽 끝에 어떻게 나열하나 고민했었는데, 저런 방법도 있었군요!! 덕분에 배웠습니당 👏 |
||
position:fixed; | ||
right:280px; | ||
} | ||
.doneBtn{ | ||
position:fixed; | ||
right:310px; | ||
} | ||
.todoItem{ | ||
display:flex; | ||
justify-content: space-between; | ||
width: 100%; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어디서 많이 보던 코드인데.....