Skip to content

Commit

Permalink
i18n(zh-cn): Update view-transitions.mdx (#11043)
Browse files Browse the repository at this point in the history
* i18n(zh-cn): Update `view-transitions.mdx`

* fix: remove duplicated line

* Update src/content/docs/zh-cn/guides/view-transitions.mdx

Co-authored-by: liruifengv <[email protected]>

---------

Co-authored-by: liruifengv <[email protected]>
  • Loading branch information
Nin3lee and liruifengv authored Mar 3, 2025
1 parent 1283ecb commit 56d53d4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/content/docs/zh-cn/guides/view-transitions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ i18nReady: true
import Since from '~/components/Since.astro'
import { Steps } from '@astrojs/starlight/components'

Astro 仅需几行代码就可以支持**可选择的,每个页面的视图过渡动画**。视图过渡动画可以在不刷新浏览器的情况下更新页面内容,并在页面之间提供无缝的动画效果。
Astro 仅需几行代码就可以支持视图过渡动画。视图过渡动画可以在不刷新浏览器的情况下更新页面内容,并在页面之间提供无缝的动画效果。而那些对 [View Transition API 缺少支持的浏览器](https://developer.mozilla.org/zh-CN/docs/Web/API/View_Transition_API#浏览器兼容性),Astro 允许你 [控制回退策略](#回退控制),来为所有访客提供最佳的体验

Astro 提供了一个 `<ClientRouter />` 路由组件,可以添加到单个页面的 `<head>` 中,以控制页面在导航到另一个页面时的过渡效果。它提供了一个轻量级的客户端路由器,[拦截导航](#客户端导航流程) 并允许你自定义页面之间的过渡效果。

Expand All @@ -23,7 +23,6 @@ Astro 的视图过渡动画支持由新的 [View Transitions](https://developer.
- 对于尚未支持视图过渡动画 API 的浏览器,可以 [控制回退行为](#回退控制)
- 自动支持 [`prefers-reduced-motion`](#prefers-reduced-motion)


:::note
默认情况下,每个页面都将使用常规的、全页的浏览器导航。你必须选择视图过渡动画,并且可以在每个页面或整个站点上使用它们。
:::
Expand Down Expand Up @@ -436,7 +435,16 @@ import { ClientRouter } from "astro:transitions";

## 回退控制

`<ClientRouter />` 路由器在支持视图过渡动画的浏览器(如 Chromium 浏览器)中表现最佳,但也包含了对其他浏览器的默认回退支持。即当浏览器不支持视图过渡动画 API 时,Astro 仍将提供基于浏览器的导航,使用其中一种回退选项来实现类似的效果。
`<ClientRouter />` 路由器在支持视图过渡动画的浏览器(如 Chromium 浏览器)中表现最佳,但也包含了对其他浏览器的默认回退支持。即使当浏览器不支持视图过渡动画 API 时,Astro 的客户端路由仍然可以使用其中一个回退选项提供来浏览器导航。

根据浏览器的支持情况,你可能需要在元素上明确的设置 `name` 或者 `animate`[`transition` 指令](#过渡动画指令) 以便在所有浏览器中获得相近的动画体验。

```astro title="src/pages/about.astro"
---
import Layout from '../layouts/LayoutUsingClientRouter.astro'
---
<title transition:animate="fade">关于我的网站</title>
```

你可以通过在 `<ClientRouter />` 组件上添加一个名为 `fallback` 的属性,并将其设置为 `swap``none`,来覆盖 Astro 的默认回退支持:

Expand Down

0 comments on commit 56d53d4

Please sign in to comment.