Repository navigation
Commit b2cb602
docs: cross-fade between pages with view transitions (#33888)
Navigating between pages in the docs app swapped the content instantly.
This enables the router's `withViewTransitions()`, so browsers that
support the View Transitions API cross-fade from the old page to the new
one. Other browsers keep the current behavior.
Changes:
- Add `withViewTransitions({skipInitialTransition: true})` to the router
config. The first page load isn't animated, since there's no previous
page to transition from.
- Add a global `prefers-reduced-motion: reduce` rule that disables the
view transition animations, so those users get an instant page swap.
Checked in Chrome against the dev server, comparing against a run with
`document.startViewTransition` removed to get the behavior without
transitions:
- Clicking a category card runs a 250ms cross-fade of the root.
- The first page load doesn't start a transition.
- Focus still moves to the new page's `focusOnNavigation` target.
- Navigating to another page with a `#fragment` still scrolls the target
heading into view, at the same position as without transitions.
- With reduced motion, the transition starts but runs no animations.
(cherry picked from commit 6064a60)1 parent 8793a4c commit b2cb602
2 files changed
Lines changed: 21 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
14 | 19 | | |
15 | 20 | | |
16 | 21 | | |
| |||
33 | 38 | | |
34 | 39 | | |
35 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
36 | 44 | | |
37 | 45 | | |
38 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
0 commit comments