Skip to content

Commit f9cb07b

Browse files
jtchen2kMartinsYongbemselfleviding
authored
Translate some chapters to [Jul 17, 2020] Part-6 (#795) (#804)
* Minor error fix in 1-js/05-data-types/02-number/article.md * Translated 2-ui/3-event-details/6-pointer-events * Translated some chapters to [Jul 17, 2020] Part-6 #795 * Translation improvement * Minor error fix in 1-js/05-data-types/02-number/article.md * Minor fix in 2-ui/3-event-details/1-mouse-events-basics * Minor fix in 2-ui/3-event-details/1-mouse-events-basics * Update 2-ui/1-document/01-browser-environment/article.md Co-authored-by: Martin <[email protected]> * Apply suggestions from code review Co-authored-by: Martin <[email protected]> * Apply suggestions from code review Took some suggestions Co-authored-by: Martin <[email protected]> * Apply suggestions from code review Commit from suggestions Co-authored-by: Martin <[email protected]> * Apply suggestions from code review Commit from suggestion Co-authored-by: bemself <[email protected]> * Update 2-ui/3-event-details/6-pointer-events/article.md Co-authored-by: bemself <[email protected]> * Apply suggestions from code review 已补充 commit。 Co-authored-by: Martin <[email protected]> * Update article.md * Update article.md * Update article.md * Update index.html * Update article.md * Update article.md * Update article.md * Update article.md * Update article.md * Update article.md Co-authored-by: Martin <[email protected]> Co-authored-by: bemself <[email protected]> Co-authored-by: LeviDing <[email protected]>
1 parent e09626b commit f9cb07b

File tree

7 files changed

+162
-162
lines changed

7 files changed

+162
-162
lines changed

Diff for: 2-ui/1-document/01-browser-environment/article.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ DOM 规范解释了文档的结构,并提供了操作文档的对象。有的
5858
```
5959

6060
```smart header="用于样式的 CSSOM"
61-
There's also a separate specification, [CSS Object Model (CSSOM)](https://www.w3.org/TR/cssom-1/) for CSS rules and stylesheets, that explains how they are represented as objects, and how to read and write them.
61+
另外也有一份针对 CSS 规则和样式表的、单独的规范 [CSS Object Model (CSSOM)](https://www.w3.org/TR/cssom-1/),这份规范解释了如何将 CSS 表示为对象,以及如何读写这些对象。
6262
63-
当我们修改文档的样式规则时,CSSOM 与 DOM 是一起使用的。但实际上,很少需要 CSSOM,因为 we rarely need to modify CSS rules from JavaScript (usually we just add/remove CSS classes, not modify their CSS rules), but that's also possible.
63+
当我们修改文档的样式规则时,CSSOM 与 DOM 是一起使用的。但实际上,很少需要 CSSOM,因为我们很少需要从 JavaScript 中修改 CSS 规则(我们通常只是添加/移除一些 CSS 类,而不是直接修改其中的 CSS 规则),但这也是可行的。
6464
```
6565

6666
## 浏览器对象模型(BOM)

Diff for: 2-ui/1-document/07-modifying-document/article.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@ DOM 修改是创建“实时”页面的关键。
4848
let textNode = document.createTextNode('Here I am');
4949
```
5050

51-
Most of the time we need to create element nodes, such as the `div` for the message.
51+
大多数情况下,我们需要为此消息创建像 `div` 这样的元素节点。
5252

5353
### 创建一条消息
5454

55-
Creating the message div takes 3 steps:
55+
创建一个消息 `div` 分为 3 个步骤:
5656

5757
```js
58-
// 1. Create <div> element
58+
// 1. 创建 <div> 元素
5959
let div = document.createElement('div');
6060

61-
// 2. Set its class to "alert"
61+
// 2. 将元素的类设置为 "alert"
6262
div.className = "alert";
6363

64-
// 3. Fill it with the content
64+
// 3. 填充消息内容
6565
div.innerHTML = "<strong>Hi there!</strong> You've read an important message.";
6666
```
6767

@@ -97,19 +97,19 @@ div.innerHTML = "<strong>Hi there!</strong> You've read an important message.";
9797
</script>
9898
```
9999

100-
Here we called `append` on `document.body`, but we can call `append` method on any other element, to put another element into it. For instance, we can append something to `<div>` by calling `div.append(anotherElement)`.
100+
在这个例子中,我们对 `document.body` 调用了 `append` 方法。不过我们可以在其他任何元素上调用 `append` 方法,以将另外一个元素放入到里面。例如,通过调用 `div.append(anotherElement)`,我们便可以在 `<div>` 末尾添加一些内容。
101101

102-
Here are more insertion methods, they specify different places where to insert:
102+
这里是更多的元素插入方法,指明了不同的插入位置:
103103

104-
- `node.append(...nodes or strings)` — 在 `node` **末尾** 插入节点或字符串,
105-
- `node.prepend(...nodes or strings)` — 在 `node` **开头** 插入节点或字符串,
106-
- `node.before(...nodes or strings)` — 在 `node` **前面** 插入节点或字符串,
107-
- `node.after(...nodes or strings)` — 在 `node` **后面** 插入节点或字符串,
108-
- `node.replaceWith(...nodes or strings)` — 将 `node` 替换为给定的节点或字符串。
104+
- `node.append(...nodes or strings)``node` **末尾** 插入节点或字符串,
105+
- `node.prepend(...nodes or strings)``node` **开头** 插入节点或字符串,
106+
- `node.before(...nodes or strings)``node` **前面** 插入节点或字符串,
107+
- `node.after(...nodes or strings)``node` **后面** 插入节点或字符串,
108+
- `node.replaceWith(...nodes or strings)``node` 替换为给定的节点或字符串。
109109

110-
Arguments of these methods are an arbitrary list of DOM nodes to insert, or text strings (that become text nodes automatically).
110+
这些方法的参数可以是一个要插入的任意的 DOM 节点列表,或者文本字符串(会被自动转换成文本节点)。
111111

112-
Let's see them in action.
112+
让我们在实际应用中看一看。
113113

114114
下面是使用这些方法将列表项添加到列表中,以及将文本添加到列表前面和后面的示例:
115115

@@ -163,7 +163,7 @@ after
163163
</script>
164164
```
165165

166-
Please note: the text is inserted "as text", not "as HTML", with proper escaping of characters such as `<`, `>`.
166+
请注意:这里的文字都被“作为文本”插入,而不是“作为 HTML 代码”。因此像 `<``>` 这样的符号都会被作转义处理来保证正确显示。
167167

168168
所以,最终的 HTML 为:
169169

@@ -179,7 +179,7 @@ Please note: the text is inserted "as text", not "as HTML", with proper escaping
179179

180180
所以,这些方法只能用来插入 DOM 节点或文本片段。
181181

182-
But what if we'd like to insert an HTML string "as html", with all tags and stuff working, in the same manner as `elem.innerHTML` does it?
182+
但如果我们想要将内容“作为 HTML 代码插入”,让内容中的所有标签和其他东西都像使用 `elem.innerHTML` 所表现的效果一样,那应该怎么办呢?
183183

184184
## insertAdjacentHTML/Text/Element
185185

Diff for: 2-ui/2-events/01-introduction-browser-events/article.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
- `mousemove` —— 当鼠标移动时。
1313

1414
**键盘事件**
15-
- `keydown` and `keyup` -- when a keyboard key is pressed and released.
15+
- `keydown` `keyup` —— 当按下和松开一个按键时。
1616

1717
**表单(form)元素事件**
1818
- `submit` —— 当访问者提交了一个 `<form>` 时。
@@ -107,7 +107,7 @@ HTML 特性不是编写大量代码的好位置,因此我们最好创建一个
107107
</script>
108108
```
109109

110-
In the first example, the HTML attribute is used to initialize the `button.onclick`, while in the second example -- the script, that's all the difference.
110+
在第一个例子中,`button.onclick` 是通过 HTML 特性(attribute)初始化的,而在第二个例子中是通过脚本初始化的。这是它们唯一的不同之处。
111111

112112
**因为这里只有一个 `onclick` 属性,所以我们无法分配更多事件处理程序。**
113113

@@ -140,7 +140,7 @@ In the first example, the HTML attribute is used to initialize the `button.oncli
140140

141141
如果你刚开始写事件 —— 请注意一些细微之处。
142142

143-
We can set an existing function as a handler:
143+
我们可以将一个现存的函数用作处理程序:
144144

145145
```js
146146
function sayThanks() {
@@ -150,7 +150,7 @@ function sayThanks() {
150150
elem.onclick = sayThanks;
151151
```
152152

153-
But be careful: the function should be assigned as `sayThanks`, not `sayThanks()`.
153+
但要注意:函数应该是以 `sayThanks` 的形式进行赋值,而不是 `sayThanks()`
154154

155155
```js
156156
// 正确

Diff for: 2-ui/2-events/05-dispatch-events/article.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,11 @@ alert(event.clientX); // undefined,未知的属性被忽略了!
213213

214214
通常事件是在队列中处理的。也就是说:如果浏览器正在处理 `onclick`,这时发生了一个新的事件,例如鼠标移动了,那么它会被排入队列,相应的 `mousemove` 处理程序将在 `onclick` 事件处理完成后被调用。
215215

216-
值得注意的例外情况就是,一个事件是在另一个事件中发起的。例如 using `dispatchEvent`. Such events are processed immediately: the new event handlers are called, and then the current event handling is resumed.
216+
值得注意的例外情况就是,一个事件是在另一个事件中发起的。例如使用 `dispatchEvent`。这类事件将会被立即处理,即在新的事件处理程序被调用之后,恢复到当前的事件处理程序。
217217

218-
For instance, in the code below the `menu-open` event is triggered during the `onclick`.
218+
例如,在下面的代码中,`menu-open` 事件是在 `onclick` 事件执行过程中被调用的。
219219

220-
It's processed immediately, without waiting for `onlick` handler to end:
220+
它会被立即执行,而不必等待 `onclick` 处理程序结束:
221221

222222

223223
```html run autorun
@@ -234,7 +234,7 @@ It's processed immediately, without waiting for `onlick` handler to end:
234234
alert(2);
235235
};
236236
237-
// triggers between 1 and 2
237+
// 在 1 和 2 之间触发
238238
document.addEventListener('menu-open', () => alert('nested'));
239239
</script>
240240
```
@@ -243,11 +243,11 @@ It's processed immediately, without waiting for `onlick` handler to end:
243243

244244
请注意,嵌套事件 `menu-open` 会在 `document` 上被捕获。嵌套事件的传播(propagation)和处理先被完成,然后处理过程才会返回到外部代码(`onclick`)。
245245

246-
这不只是与 `dispatchEvent` 有关,还有其他情况。If an event handler calls methods that trigger to other events -- they are too processed synchronously, in a nested fashion.
246+
这不只是与 `dispatchEvent` 有关,还有其他情况。如果一个事件处理程序进一步触发了其它的事件 —— 它们同样也会被以嵌套的方式同步处理。
247247

248-
Let's say we don't like it. We'd want `onclick` to be fully processed first, independently from `menu-open` or any other nested events.
248+
不过有时候,这并不是我们期望的结果。我们想让 `onclick` 不受 `menu-open` 或者其它嵌套事件的影响,优先被处理完毕。
249249

250-
然后,我们可以将 `dispatchEvent`(或另一个触发事件的调用)放在 `onclick` 末尾,或者最好将其包装到零延迟的 `setTimeout` 中:
250+
那么,我们就可以将 `dispatchEvent`(或另一个触发事件的调用)放在 `onclick` 末尾,或者最好将其包装到零延迟的 `setTimeout` 中:
251251

252252
```html run
253253
<button id="menu">Menu (click me)</button>

Diff for: 2-ui/3-event-details/1-mouse-events-basics/article.md

+19-19
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,32 @@
5050

5151
与点击相关的事件始终具有 `button` 属性,该属性允许获取确切的鼠标按钮。
5252

53-
We usually don't use it for `click` and `contextmenu` events, because the former happens only on left-click, and the latter -- only on right-click.
53+
通常我们不在 `click` `contextmenu` 事件中使用这一属性,因为前者只在单击鼠标左键时触发,后者只在单击鼠标右键时触发。
5454

55-
From the other hand, `mousedown` and `mouseup` handlers we may need `event.button`, because these events trigger on any button, so `button` allows to distinguish between "right-mousedown" and "left-mousedown".
55+
不过,在 `mousedown` `mouseup` 事件中则可能需要用到 `event.button`,因为这两个事件在任何按键上都会触发,所以我们可以使用 `button` 属性来区分是左键单击还是右键单击。
5656

57-
The possible values of `event.button` are:
57+
`event.button` 的所有可能值如下:
5858

59-
| Button state | `event.button` |
59+
| 鼠标按键状态 | `event.button` |
6060
|--------------|----------------|
61-
| Left button (primary) | 0 |
62-
| Middle button (auxillary) | 1 |
63-
| Right button (secondary) | 2 |
64-
| X1 button (back) | 3 |
65-
| X2 button (forward) | 4 |
61+
| 左键 (主要按键) | 0 |
62+
| 中键 (辅助按键) | 1 |
63+
| 右键 (次要按键) | 2 |
64+
| X1 键 (后退按键) | 3 |
65+
| X2 键 (前进按键) | 4 |
6666

67-
Most mouse devices only have the left and right buttons, so possible values are `0` or `2`. Touch devices also generate similar events when one taps on them.
67+
大多数鼠标设备只有左键和右键,对应的值就是 `0` `2`。触屏设备中的点按操作也会触发类似的事件。
6868

69-
Also there's `event.buttons` property that has all currently pressed buttons as an integer, one bit per button. In practice this property is very rarely used, you can find details at [MDN](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons) if you ever need it.
69+
另外,还有一个 `event.buttons` 属性,其中以整数的形式存储着当前所有按下的鼠标按键,每个按键一个比特位。在实际开发中,很少会用到这个属性,如果有需要的话,你可以在 [MDN](https://developer.mozilla.org/zh-CN/docs/Web/API/MouseEvent/buttons) 中找到更多细节。
7070

71-
```warn header="The outdated `event.which`"
72-
Old code may use `event.which` property that's an old non-standard way of getting a button, with possible values:
71+
```warn header="过时的 `event.which`"
72+
一些老代码可能会使用 `event.which` 属性来获得按下的按键。这是一个古老的非标准的方式,具有以下可能值:
7373

74-
- `event.which == 1` – left button,
75-
- `event.which == 2` – middle button,
76-
- `event.which == 3` – right button.
74+
- `event.which == 1` —— 鼠标左键,
75+
- `event.which == 2` —— 鼠标中键,
76+
- `event.which == 3` —— 鼠标右键。
7777

78-
As of now, `event.which` is deprecated, we shouldn't use it.
78+
现在,`event.which` 已经被弃用了,不应再使用它。
7979
```
8080
8181
## 组合键:shift,alt,ctrl,meta
@@ -136,9 +136,9 @@ As of now, `event.which` is deprecated, we shouldn't use it.
136136
1. 相对于窗口的坐标:`clientX``clientY`
137137
2. 相对于文档的坐标:`pageX``pageY`
138138

139-
We already covered the difference between them in the chapter <info:coordinates>.
139+
我们已经在 <info:coordinates> 中解释过它们之间的区别。
140140

141-
In short, document-relative coordinates `pageX/Y` are counted from the left-upper corner of the document, and do not change when the page is scrolled, while `clientX/Y` are counted from the current window left-upper corner. When the page is scrolled, they change.
141+
简而言之,相对于文档的坐标 `pageX/Y` 以文档的左上角为参照物,并且同一位置的坐标不随页面的滚动而改变。相对于窗口的坐标 `clientX/Y` 以当前窗口的左上角为参照物,并且同一位置的坐标会随着页面的滚动而改变。
142142

143143
例如,如果我们有一个大小为 500x500 的窗口,并且鼠标在左上角,那么 `clientX``clientY` 均为 `0`,无论页面如何滚动。
144144

0 commit comments

Comments
 (0)