Skip to content

Commit 554d730

Browse files
Merge pull request #1411 from javascript-tutorial/1313
[이벤트 위임] 과제4 번역(#1313)
2 parents 68e1c59 + 6aaa9f3 commit 554d730

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

2-ui/2-events/03-event-delegation/4-behavior-tooltip/solution.view/index.html

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<style>
77
body {
88
height: 2000px;
9-
/* make body scrollable, the tooltip should work after the scroll */
9+
/* body 높이를 일부러 키워서 스크롤이 나타나도록 하였습니다. 스크롤 위치에 상관없이 요구사항대로 툴팁이 나타나야 합니다.*/
1010
}
1111

1212
.tooltip {
@@ -25,13 +25,13 @@
2525

2626
<body>
2727

28-
<p>LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa</p>
29-
<p>LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa</p>
28+
<p>동해물과 백두산이 마르고 닳도록 하느님이 보우하사 우리나라 만세</p>
29+
<p>무궁화 삼천리 화려강산 대한사람 대한으로 길이 보전하세</p>
3030

31-
<button data-tooltip="the tooltip is longer than the element">Short button</button>
32-
<button data-tooltip="HTML<br>tooltip">One more button</button>
31+
<button data-tooltip="버튼 요소 길이보다 툴팁 길이가 훨씬 기네요.">짧은 버튼</button>
32+
<button data-tooltip="두 줄짜리<br>툴팁">...또 다른 버튼...</button>
3333

34-
<p>Scroll the page to make buttons appear on the top, check if the tooltips show up correctly.</p>
34+
<p>버튼이 화면 맨 위쪽에 위치하도록 스크롤을 움직여보고, 그 상태에서 툴팁이 제대로 버튼 아래에 나타나는지 확인해보세요.</p>
3535

3636

3737
<script>
@@ -40,25 +40,25 @@
4040
document.onmouseover = function(event) {
4141
let target = event.target;
4242

43-
// if we have tooltip HTML...
43+
// data-tooltip 속성이 있는 요소
4444
let tooltipHtml = target.dataset.tooltip;
4545
if (!tooltipHtml) return;
4646

47-
// ...create the tooltip element
47+
// 툴팁 요소를 만듭니다.
4848

4949
tooltipElem = document.createElement('div');
5050
tooltipElem.className = 'tooltip';
5151
tooltipElem.innerHTML = tooltipHtml;
5252
document.body.append(tooltipElem);
5353

54-
// position it above the annotated element (top-center)
54+
// 툴팁 요소를 data-tooltip 속성이 있는 요소 위, 가운데에 위치시킵니다.
5555
let coords = target.getBoundingClientRect();
5656

5757
let left = coords.left + (target.offsetWidth - tooltipElem.offsetWidth) / 2;
58-
if (left < 0) left = 0; // don't cross the left window edge
58+
if (left < 0) left = 0; // 툴팁이 창 왼쪽 가장자리를 넘지 않도록 합니다.
5959

6060
let top = coords.top - tooltipElem.offsetHeight - 5;
61-
if (top < 0) { // if crossing the top window edge, show below instead
61+
if (top < 0) { // 툴팁이 창 위로 넘치면 요소 아래에 보여줍니다.
6262
top = coords.top + target.offsetHeight + 5;
6363
}
6464

2-ui/2-events/03-event-delegation/4-behavior-tooltip/source.view/index.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<style>
77
body {
88
height: 2000px;
9-
/* 높이를 일부러 키워서 스크롤이 나타나도록 하였습니다. 스크롤 위치에 상관없이 요구사항대로 툴팁이 나타나야 합니다. */
9+
/* body 높이를 일부러 키워서 스크롤이 나타나도록 하였습니다. 스크롤 위치에 상관없이 요구사항대로 툴팁이 나타나야 합니다.*/
1010
}
1111

1212
.tooltip {
@@ -26,17 +26,17 @@
2626

2727
<body>
2828

29-
<p>LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa</p>
30-
<p>LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa LaLaLa</p>
29+
<p>동해물과 백두산이 마르고 닳도록 하느님이 보우하사 우리나라 만세</p>
30+
<p>무궁화 삼천리 화려강산 대한사람 대한으로 길이 보전하세</p>
3131

32-
<button data-tooltip="the tooltip is longer than the element">Short button</button>
32+
<button data-tooltip="버튼 요소 길이보다 툴팁 길이가 훨씬 기네요.">짧은 버튼</button>
3333
<button data-tooltip="두 줄짜리<br>툴팁">...또 다른 버튼...</button>
3434

35-
<p>Scroll the page to make buttons appear on the top, check if the tooltips show up correctly.</p>
35+
<p>버튼이 화면 맨 위쪽에 위치하도록 스크롤을 움직여보고, 그 상태에서 툴팁이 제대로 버튼 아래에 나타나는지 확인해보세요.</p>
3636

3737

3838
<script>
39-
// ...your code...
39+
// ...여기에 코드를 작성하세요...
4040
</script>
4141

4242
</body>

2-ui/2-events/03-event-delegation/4-behavior-tooltip/task.md

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

33
---
44

5-
# Tooltip behavior
5+
# 툴팁 보여주기
66

77
툴팁(tooltip)을 보여주는 JS 코드를 작성해봅시다.
88

9-
`data-tooltip` 속성이 있는 요소에 마우스를 가져다 대면 툴팁이 보여야 하고, 마우스 커서가 요소에서 떠나면 툴팁이 사라져야 합니다.
9+
`data-tooltip` 속성이 있는 요소에 마우스를 가져다 대면 툴팁이 보여야 하고, 마우스 커서가 요소에서 떠나면 툴팁이 사라져야 합니다.
1010

1111
`data-tooltip` 속성은 다음 HTML처럼 추가할 수 있습니다.
1212
```html
13-
<button data-tooltip="the tooltip is longer than the element">Short button</button>
13+
<button data-tooltip="버튼 요소 길이보다 툴팁 길이가 훨씬 기네요.">짧은 버튼</button>
1414
<button data-tooltip="두 줄짜리<br>툴팁">...또 다른 버튼...</button>
1515
```
1616

17-
Should work like this:
17+
답을 잘 작성했다면 아래 예시처럼 동작해야 합니다.
1818

1919
[iframe src="solution" height=200 border=1]
2020

2121
`data-tooltip`이 있는 요소엔 텍스트만 있다고 가정하겠습니다. 요소 안에 다른 태그가 있는 경우는 생각하지 않기로 합시다.
2222

23-
Details:
23+
자세한 요구사항은 다음과 같습니다.
2424

2525
- 툴팁과 요소의 간격은 `5px`입니다.
2626
- 가능하면 툴팁은 요소를 기준으로 중앙에 있도록 합시다.
27-
- The tooltip should not cross window edges. Normally it should be above the element, but if the element is at the page top and there's no space for the tooltip, then below it.
27+
- 툴팁은 창 크기보다 커질 수 없습니다. 일반적인 경우라면 툴팁은 요소 위에 있을 텐데, 요소가 창 맨 위에 있어서 툴팁을 보여줄 공간이 없다면 툴팁은 요소 아래에 나타납니다.
2828
- 툴팁안에 띄울 콘텐츠는 `data-tooltip` 속성에서 가져옵니다. 속성값은 HTML일 수 있습니다.
2929

30-
You'll need two events here:
30+
원하는 기능을 구현하려면 다음 두 가지 이벤트가 필요합니다.
3131
- `mouseover` -- 요소 안으로 포인터가 이동할 때 발생하는 이벤트
3232
- `mouseout`-- 요소 밖으로 포인터가 이동할 때 발생하는 이벤트
3333

3434
이벤트 위임을 사용해서 두 개의 핸들러만으로 원하는 기능을 구현하세요. `document`에 핸들러를 추가해 `data-tooltip` 속성이 있는 요소 안이나 밖으로 마우스 포인터가 이동하는 경우를 모두 감지하고 두 핸들러를 통해 툴팁을 보여주거나 감추시면 됩니다.
3535

36-
After the behavior is implemented, even people unfamiliar with JavaScript can add annotated elements.
36+
이렇게 툴팁 기능을 구현해 놓으면 자바스크립트에 익숙하지 않은 사람도 원하는 요소에 쉽게 툴팁을 보여줄 수 있을 겁니다.
3737

3838
P.S. 한 번에 한 개의 툴팁 만 보여줄 수 있습니다.

0 commit comments

Comments
 (0)