Skip to content

Commit 056a0fa

Browse files
authored
docs:11-dịch-2-advanced-svelte-transitions (sveltevietnam#74)
1 parent bd392b4 commit 056a0fa

File tree

23 files changed

+72
-68
lines changed

23 files changed

+72
-68
lines changed

content/tutorial/02-advanced-svelte/02-transitions/01-transition/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
---
2-
title: The transition directive
2+
title: Chỉ thị chuyển tiếp
33
---
44

5-
We can make more appealing user interfaces by gracefully transitioning elements into and out of the DOM. Svelte makes this very easy with the `transition` directive.
5+
Chúng ta có thể tạo giao diện người dùng hấp dẫn hơn bằng cách chuyển tiếp nhẹ các phần tử vào và ra khỏi DOM. Svelte làm điều này rất dễ dàng với chỉ thị `transition`.
6+
7+
Đầu tiên, nhập hàm `fade` từ `svelte/transition`...
68

7-
First, import the `fade` function from `svelte/transition`...
89

910
```svelte
1011
/// file: App.svelte
@@ -14,7 +15,7 @@ First, import the `fade` function from `svelte/transition`...
1415
</script>
1516
```
1617

17-
...then add it to the `<p>` element:
18+
...sau đó thêm vào phần tử `<p>`:
1819

1920
```svelte
2021
/// file: App.svelte

content/tutorial/02-advanced-svelte/02-transitions/01-transition/app-a/src/lib/App.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<label>
66
<input type="checkbox" bind:checked={visible} />
7-
visible
7+
hiện
88
</label>
99

1010
{#if visible}

content/tutorial/02-advanced-svelte/02-transitions/01-transition/app-b/src/lib/App.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<label>
77
<input type="checkbox" bind:checked={visible} />
8-
visible
8+
hiện
99
</label>
1010

1111
{#if visible}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
title: Adding parameters
2+
title: Thêm tham số
33
---
44

5-
Transition functions can accept parameters. Replace the `fade` transition with `fly`...
5+
Hàm chuyển tiếp có thể chấp nhận các tham số. Thay thế chuyển tiếp `fade` bằng `fly`...
66

77
```svelte
88
/// file: App.svelte
@@ -12,7 +12,7 @@ Transition functions can accept parameters. Replace the `fade` transition with `
1212
</script>
1313
```
1414

15-
...and apply it to the `<p>` along with some options:
15+
... và áp dụng nó cho phần tử <p> cùng với một số tùy chọn:
1616

1717
```svelte
1818
/// file: App.svelte
@@ -21,4 +21,4 @@ Transition functions can accept parameters. Replace the `fade` transition with `
2121
</p>
2222
```
2323

24-
Note that the transition is _reversible_ — if you toggle the checkbox while the transition is ongoing, it transitions from the current point, rather than the beginning or the end.
24+
Lưu ý: chuyển tiếp có thể _đảo ngược_ — nếu bạn thay đổi checkbox trong khi chuyển động đang diễn ra, nó sẽ chuyển tiếp từ điểm hiện tại, thay vì từ đầu hoặc cuối.

content/tutorial/02-advanced-svelte/02-transitions/02-adding-parameters-to-transitions/app-b/src/lib/App.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<label>
77
<input type="checkbox" bind:checked={visible} />
8-
visible
8+
hiện
99
</label>
1010

1111
{#if visible}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
2-
title: In and out
2+
title: In out
33
---
44

5-
Instead of the `transition` directive, an element can have an `in` or an `out` directive, or both together. Import `fade` alongside `fly`...
5+
Thay vì sử dụng chỉ thị `transition`, một phần tử có thể có một chỉ thị `in` hoặc một chỉ thị `out`, hoặc cả hai cùng một lúc. Import `fade` cùng với `fly`...
66

77
```js
88
/// file: App.svelte
99
import { +++fade+++, fly } from 'svelte/transition';
1010
```
1111

12-
...then replace the `transition` directive with separate `in` and `out` directives:
12+
... sau đó thay thế chỉ thị `transition` bằng các chỉ thị `in` `out` riêng lẻ:
1313

1414
```svelte
1515
/// file: App.svelte
@@ -18,4 +18,4 @@ import { +++fade+++, fly } from 'svelte/transition';
1818
</p>
1919
```
2020

21-
In this case, the transitions are _not_ reversed.
21+
Trong trường hợp này, các chuyển tiếp không được _đảo ngược_.

content/tutorial/02-advanced-svelte/02-transitions/03-in-and-out/app-b/src/lib/App.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<label>
77
<input type="checkbox" bind:checked={visible} />
8-
visible
8+
hiện
99
</label>
1010

1111
{#if visible}

content/tutorial/02-advanced-svelte/02-transitions/04-custom-css-transitions/README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
title: Custom CSS transitions
2+
title: Tùy biến CSS chuyển tiếp
33
---
44

5-
The `svelte/transition` module has a handful of built-in transitions, but it's very easy to create your own. By way of example, this is the source of the `fade` transition:
5+
Module `svelte/transition` có một số chuyển tiếp tích hợp sẵn, nhưng rất dễ tạo ra chuyển tiếp riêng của bạn. Qua ví dụ, đây là mã nguồn của chuyển tiếp `fade`:
66

77
```js
88
/// no-file
@@ -17,19 +17,19 @@ function fade(node, { delay = 0, duration = 400 }) {
1717
}
1818
```
1919

20-
The function takes two argumentsthe node to which the transition is applied, and any parameters that were passed in — and returns a transition object which can have the following properties:
20+
Hàm nhận hai đối số — node mà chuyển tiếp được áp dụng và bất kỳ tham số nào được truyền vào — và trả về một đối tượng chuyển tiếp có thể có các thuộc tính sau:
2121

22-
- `delay`milliseconds before the transition begins
23-
- `duration`length of the transition in milliseconds
24-
- `easing`a `p => t` easing function (see the chapter on [tweening](/tutorial/tweens))
25-
- `css`a `(t, u) => css` function, where `u === 1 - t`
26-
- `tick`a `(t, u) => {...}` function that has some effect on the node
22+
- `delay`số mili giây trước khi chuyển tiếp bắt đầu
23+
- `duration`độ dài của chuyển động trong mili giây
24+
- `easing`một hàm easing `p => t` (xem chương [tweening](/tutorial/tweens))
25+
- `css`một hàm `(t, u) => css`, trong đó `u === 1 - t`
26+
- `tick`một hàm `(t, u) => {...}` có một số ảnh hưởng đối với node
2727

28-
The `t` value is `0` at the beginning of an intro or the end of an outro, and `1` at the end of an intro or beginning of an outro.
28+
Giá trị `t` `0` ở đầu của một intro hoặc cuối của một outro, `1` ở cuối của một intro hoặc đầu của một outro.
2929

30-
Most of the time you should return the `css` property and _not_ the `tick` property, as CSS animations run off the main thread to prevent jank where possible. Svelte 'simulates' the transition and constructs a CSS animation, then lets it run.
30+
Thường thì bạn nên trả về thuộc tính `css` _không_ phải thuộc tính `tick`, vì các hoạt ảnh CSS chạy ngoài luồng chính để ngăn chặn gián đoạn khi có thể. Svelte 'mô phỏng' chuyển tiếp và xây dựng một hoạt ảnh CSS, sau đó để nó chạy.
3131

32-
For example, the `fade` transition generates a CSS animation somewhat like this:
32+
Ví dụ, chuyển tiếp `fade` tạo ra một hoạt ảnh CSS giống như sau:
3333

3434
```css
3535
/// no-file
@@ -40,7 +40,7 @@ For example, the `fade` transition generates a CSS animation somewhat like this:
4040
100% { opacity: 1 }
4141
```
4242

43-
We can get a lot more creative though. Let's make something truly gratuitous:
43+
Chúng ta có thể sáng tạo nhiều hơn. Hãy tạo ra điều gì đó thực sự miễn phí:
4444

4545
```svelte
4646
/// file: App.svelte
@@ -69,4 +69,4 @@ We can get a lot more creative though. Let's make something truly gratuitous:
6969
</script>
7070
```
7171

72-
Remember: with great power comes great responsibility.
72+
Nhớ rằng: quyền lực lớn đến từ trách nhiệm lớn.

content/tutorial/02-advanced-svelte/02-transitions/04-custom-css-transitions/app-a/src/lib/App.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<label>
1515
<input type="checkbox" bind:checked={visible} />
16-
visible
16+
hiện
1717
</label>
1818

1919
{#if visible}

content/tutorial/02-advanced-svelte/02-transitions/04-custom-css-transitions/app-b/src/lib/App.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
<label>
2626
<input type="checkbox" bind:checked={visible} />
27-
visible
27+
hiện
2828
</label>
2929

3030
{#if visible}

content/tutorial/02-advanced-svelte/02-transitions/05-custom-js-transitions/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
---
2-
title: Custom JS transitions
2+
title: Tùy biến JS chuyển tiếp
33
---
44

5-
While you should generally use CSS for transitions as much as possible, there are some effects that can't be achieved without JavaScript, such as a typewriter effect:
5+
Mặc dù bạn nên sử dụng CSS cho chuyển tiếp nhiều nhất có thể, có một số hiệu ứng không thể chạy được mà không có JavaScript, như hiệu ứng máy đánh chữ:
6+
67

78
```js
89
/// file: App.svelte
910
function typewriter(node, { speed = 1 }) {
1011
const valid = node.childNodes.length === 1 && node.childNodes[0].nodeType === Node.TEXT_NODE;
1112

1213
if (!valid) {
13-
throw new Error(`This transition only works on elements with a single text node child`);
14+
throw new Error(`Quá trình chuyển tiếp này chỉ hoạt động trên các phần tử có một node văn bản con`);
1415
}
1516

1617
+++const text = node.textContent;

content/tutorial/02-advanced-svelte/02-transitions/05-custom-js-transitions/app-a/src/lib/App.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
const valid = node.childNodes.length === 1 && node.childNodes[0].nodeType === Node.TEXT_NODE;
66
77
if (!valid) {
8-
throw new Error(`This transition only works on elements with a single text node child`);
8+
throw new Error(`Quá trình chuyển tiếp này chỉ hoạt động trên các phần tử có một node văn bản con`);
99
}
1010
1111
return {};
@@ -14,7 +14,7 @@
1414

1515
<label>
1616
<input type="checkbox" bind:checked={visible} />
17-
visible
17+
hiện
1818
</label>
1919

2020
{#if visible}

content/tutorial/02-advanced-svelte/02-transitions/05-custom-js-transitions/app-b/src/lib/App.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
const valid = node.childNodes.length === 1 && node.childNodes[0].nodeType === Node.TEXT_NODE;
66
77
if (!valid) {
8-
throw new Error(`This transition only works on elements with a single text node child`);
8+
throw new Error(`Quá trình chuyển tiếp này chỉ hoạt động trên các phần tử có một node văn bản con`);
99
}
1010
1111
const text = node.textContent;
@@ -23,7 +23,7 @@
2323

2424
<label>
2525
<input type="checkbox" bind:checked={visible} />
26-
visible
26+
hiện
2727
</label>
2828

2929
{#if visible}

content/tutorial/02-advanced-svelte/02-transitions/06-transition-events/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
title: Transition events
2+
title: Các sự kiện chuyển tiếp
33
---
44

5-
It can be useful to know when transitions are beginning and ending. Svelte dispatches events that you can listen to like any other DOM event:
5+
Việc biết khi nào chuyển tiếp bắt đầu và kết thúc có thể hữu ích. Svelte phát ra các sự kiện mà bạn có thể lắng nghe giống như bất kỳ sự kiện DOM nào khác:
66

77
```svelte
88
/// file: App.svelte
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
---
2-
title: Global transitions
2+
title: Chuyển tiếp toàn cục
33
---
44

5-
Ordinarily, transitions will only play on elements when their direct containing block is added or destroyed. In the example here, toggling the visibility of the entire list does not apply transitions to individual list elements.
5+
Thường thì, các chuyển tiếp chỉ hoạt động trên các phần tử khi khối chứa trực tiếp của chúng được thêm vào hoặc hủy bỏ. Trong ví dụ này, việc chuyển đổi khả năng nhìn thấy của toàn bộ danh sách không áp dụng các chuyển tiếp cho các phần tử danh sách cục bộ.
66

7-
Instead, we'd like transitions to not only play when individual items are added and removed with the slider but also when we toggle the checkbox.
87

9-
We can achieve this with a _global_ transition, which plays when _any_ block containing the transitions is added or removed:
8+
Thay vào đó, chúng ta muốn các chuyển tiếp không chỉ hoạt động khi các mục cục bộ được thêm và loại bỏ với thanh trượt mà còn khi chúng ta chuyển đổi checkbox.
9+
10+
Chúng ta có thể làm được điều này với một chuyển tiếp _toàn cục_, chạy khi _bất kỳ_ khối chứa các chuyển tiếp nào được thêm hoặc xóa:
1011

1112
```svelte
1213
/// file: App.svelte
@@ -15,4 +16,4 @@ We can achieve this with a _global_ transition, which plays when _any_ block con
1516
</div>
1617
```
1718

18-
> In Svelte 3, transitions were global by default and you had to use the `|local` modifier to make them local.
19+
> Trong Svelte 3, các chuyển tiếp mặc định là toàn cục (global) và bạn phải sử dụng modifier `|local` để làm chúng trở thành chuyển tiếp cục bộ.

content/tutorial/02-advanced-svelte/02-transitions/07-global-transitions/app-a/src/lib/App.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<label>
1010
<input type="checkbox" bind:checked={showItems} />
11-
show list
11+
xem danh sách
1212
</label>
1313

1414
<label>

content/tutorial/02-advanced-svelte/02-transitions/07-global-transitions/app-b/src/lib/App.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<label>
1010
<input type="checkbox" bind:checked={showItems} />
11-
show list
11+
xem danh sách
1212
</label>
1313

1414
<label>

content/tutorial/02-advanced-svelte/02-transitions/08-key-blocks/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
---
2-
title: Key blocks
2+
title: Key blocks (khối khóa)
33
---
44

5-
Key blocks destroy and recreate their contents when the value of an expression changes. This is useful if you want an element to play its transition whenever a value changes instead of only when the element enters or leaves the DOM.
5+
Các khối khóa (key blocks) hủy và tạo lại nội dung của chúng khi giá trị của biểu thức thay đổi. Điều này rất hữu ích trong trường hợp bạn muốn một phần tử chạy hiệu ứng chuyển tiếp mỗi khi giá trị thay đổi thay vì chỉ khi phần tử vào hoặc rời khỏi DOM.
6+
7+
Ở đây, ví dụ, chúng ta muốn chạy hiệu ứng chuyển tiếp `typewriter` từ `transition.js` mỗi khi thông báo tải, tức là `i`, thay đổi. Bọc phần tử `<p>` trong một khối khóa:
68

7-
Here, for example, we'd like to play the `typewriter` transition from `transition.js` whenever the loading message, i.e. `i` changes. Wrap the `<p>` element in a key block:
89

910
```svelte
1011
/// file: App.svelte

content/tutorial/02-advanced-svelte/02-transitions/08-key-blocks/app-a/src/lib/App.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
});
1818
</script>
1919

20-
<h1>loading...</h1>
20+
<h1>đang tải...</h1>
2121

2222
<p in:typewriter={{ speed: 10 }}>
2323
{messages[i] || ''}

content/tutorial/02-advanced-svelte/02-transitions/08-key-blocks/app-a/src/lib/transition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export function typewriter(node, { speed = 1 }) {
22
const valid = node.childNodes.length === 1 && node.childNodes[0].nodeType === Node.TEXT_NODE;
33

44
if (!valid) {
5-
throw new Error(`This transition only works on elements with a single text node child`);
5+
throw new Error(`Quá trình chuyển tiếp này chỉ hoạt động trên các phần tử có một node văn bản con`);
66
}
77

88
const text = node.textContent;

content/tutorial/02-advanced-svelte/02-transitions/08-key-blocks/app-b/src/lib/App.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
});
1818
</script>
1919

20-
<h1>loading...</h1>
20+
<h1>đang tải...</h1>
2121

2222
{#key i}
2323
<p in:typewriter={{ speed: 10 }}>
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
2-
title: Deferred transitions
2+
title: Chuyển tiếp trì hoãn
33
---
44

5-
A particularly powerful feature of Svelte's transition engine is the ability to _defer_ transitions, so that they can be coordinated between multiple elements.
5+
Một tính năng mạnh mẽ của hệ thống chuyển tiếp của Svelte là khả năng _trì hoãn_ các hiệu ứng chuyển tiếp, giúp chúng có thể được đồng bộ giữa nhiều phần tử.
66

7-
Take this pair of todo lists, in which toggling a todo sends it to the opposite list. In the real world, objects don't behave like that — instead of disappearing and reappearing in another place, they move through a series of intermediate positions. Using motion can go a long way towards helping users understand what's happening in your app.
7+
Xem xét cặp danh sách todo này, trong đó việc chuyển đổi một todo gửi nó đến danh sách khác. Trong thực tế, các đối tượng không hoạt động như vậy — thay vì biến mất và xuất hiện lại ở một nơi khác, chúng di chuyển qua một loạt các vị trí trung gian. Sử dụng chuyển động có thể giúp người dùng hiểu được điều gì đang xảy ra trong ứng dụng của bạn.
88

9-
We can achieve this effect using the `crossfade` function, as seen in `transition.js`, which creates a pair of transitions called `send` and `receive`. When an element is 'sent', it looks for a corresponding element being 'received', and generates a transition that transforms the element to its counterpart's position and fades it out. When an element is 'received', the reverse happens. If there is no counterpart, the `fallback` transition is used.
9+
Chúng ta có thể tạo được hiệu ứng này bằng cách sử dụng hàm `crossfade` như trong `transition.js`, tạo ra một cặp chuyển tiếp gọi là `send` `receive`. Khi một phần tử được 'gửi', nó sẽ tìm kiếm một phần tử tương ứng đang được 'nhận', và tạo ra một chuyển động chuyển đổi phần tử đó đến vị trí của phần tử đối tác và làm mờ nó đi. Khi một phần tử được 'nhận', điều ngược lại sẽ xảy ra. Nếu không có phần tử đối tác, chuyển tiếp `fallback` sẽ được sử dụng.
1010

11-
Open `TodoList.svelte`. First, import the `send` and `receive` transitions from transition.js:
11+
Mở `TodoList.svelte`. Đầu tiên, nhập các chuyển tiếp `send` `receive` từ `transition.js`:
1212

1313
```svelte
1414
/// file: TodoList.svelte
@@ -20,7 +20,7 @@ Open `TodoList.svelte`. First, import the `send` and `receive` transitions from
2020
</script>
2121
```
2222

23-
Then, add them to the `<li>` element, using the `todo.id` property as a key to match the elements:
23+
Sau đó, thêm chúng vào phần tử <li>, sử dụng thuộc tính `todo.id` làm khóa để phù hợp các phần tử:
2424

2525
```svelte
2626
/// file: TodoList.svelte
@@ -31,4 +31,4 @@ Then, add them to the `<li>` element, using the `todo.id` property as a key to m
3131
>
3232
```
3333

34-
Now, when you toggle items, they move smoothly to their new location. The non-transitioning items still jump around awkwardly — we can fix that in the next chapter.
34+
Bây giờ, khi bạn chuyển đổi các mục, chúng sẽ di chuyển mượt mà đến vị trí mới của chúng. Các mục không chuyển tiếp vẫn nhảy lên xung quanh một cách không thoải mái — chúng ta có thể sửa nó trong chương tiếp theo.

0 commit comments

Comments
 (0)