Skip to content

Commit df82a92

Browse files
[이벤트 위임] 과제2 번역 (#1311)
1 parent 6096c1e commit df82a92

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The solution has two parts.
1+
해답은 두 파트로 나뉩니다.
22

3-
1. Wrap every tree node title into `<span>`. Then we can CSS-style them on `:hover` and handle clicks exactly on text, because `<span>` width is exactly the text width (unlike without it).
4-
2. Set a handler to the `tree` root node and handle clicks on that `<span>` titles.
3+
1. 트리에 있는 모든 텍스트를 `<span>`이 감싸도록 합니다. 이렇게 하면 CSS `:hover`를 사용해 마우스 오버 시 글씨를 굴게 해주는 효과를 줄 수 있고 `<span>`이 차지하는 너비가 텍스트의 너비와 정확히 일치하기 때문에 텍스트에만 클릭 이벤트가 동작하도록 할 수 있습니다.
4+
2. 루트 노드인 `tree`에 핸들러를 추가하고 클릭 이벤트가 `<span>`으로 감싼 텍스트에만 동작하도록 합니다.

2-ui/2-events/03-event-delegation/2-sliding-tree/solution.view/index.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,22 @@
5454
</ul>
5555

5656
<script>
57-
// move all text into <span>
58-
// they occupy exactly the place necessary for the text,
57+
// 텍스트 전부를 <span>이 감싸도록 합니다.
5958
for (let li of tree.querySelectorAll('li')) {
6059
let span = document.createElement('span');
6160
li.prepend(span);
62-
span.append(span.nextSibling); // move the text node into span
61+
span.append(span.nextSibling); // 텍스트 노드를 span 안으로 옮깁니다.
6362
}
6463

65-
// catch clicks on whole tree
64+
// 트리 전체의 클릭 이벤트를 감지하는 리스너를 만듭니다.
6665
tree.onclick = function(event) {
6766

6867
if (event.target.tagName != 'SPAN') {
6968
return;
7069
}
7170

7271
let childrenContainer = event.target.parentNode.querySelector('ul');
73-
if (!childrenContainer) return; // no children
72+
if (!childrenContainer) return; // 자손 노드가 없는 경우
7473

7574
childrenContainer.hidden = !childrenContainer.hidden;
7675
}

2-ui/2-events/03-event-delegation/2-sliding-tree/source.view/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,9 @@
4242
</li>
4343
</ul>
4444

45+
<script>
46+
// ...여기에 코드를 작성하세요...
47+
</script>
48+
4549
</body>
4650
</html>

2-ui/2-events/03-event-delegation/2-sliding-tree/task.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ importance: 5
22

33
---
44

5-
# Tree menu
5+
# 트리 메뉴 구현하기
66

7-
Create a tree that shows/hides node children on click:
7+
노드를 클릭하면 자손 노드가 보이거나 숨겨지는 트리 메뉴를 구현해보세요.
88

99
[iframe border=1 src="solution"]
1010

11-
Requirements:
11+
구체적인 요구사항은 다음과 같습니다.
1212

13-
- Only one event handler (use delegation)
14-
- A click outside the node title (on an empty space) should not do anything.
13+
- 단 하나의 이벤트 핸들러(이벤트 위임 사용하기)
14+
- 노드(텍스트) 바깥(빈 곳)을 클릭하면 아무 일도 일어나지 않아야 합니다.

0 commit comments

Comments
 (0)