Skip to content

Commit ba0ca16

Browse files
committed
updates
1 parent 4c82089 commit ba0ca16

3 files changed

Lines changed: 156 additions & 128 deletions

File tree

src/content/docs/basics/hide-and-seek.mdx

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -65,30 +65,31 @@ main {
6565
Here is an interesting quirk: Scroll down a bit so part of the page content moves beneath the fixed search box at the top of the page.
6666

6767
<Media>
68-
<div class="small">
69-
<span class="light:sl-hidden">
70-
![Searchbox hides main area](@/assets/hide-and-seek/_hidden-dark.png)
71-
</span>
72-
<span class="dark:sl-hidden">
73-
![Searchbox hides main area](@/assets/hide-and-seek/_hidden-light.png)
74-
</span>
75-
</div>
76-
<p slot="caption">Text scrolls beneath the header</
77-
p>
68+
<div class="small">
69+
<span class="light:sl-hidden">
70+
![Searchbox hides main area](@/assets/hide-and-seek/_hidden-dark.png)
71+
</span>
72+
<span class="dark:sl-hidden">
73+
![Searchbox hides main area](@/assets/hide-and-seek/_hidden-light.png)
74+
</span>
75+
</div>
76+
<p slot="caption">Text scrolls beneath the header</p>
7877
</Media>
7978

8079
Now navigate to a different page. During the view transition, the `::view-transition-group(main)` pseudo-element, along with its old and new images, enters the view transition layer. Since these images are taller than the viewport, they obscure the search box momentarily.
8180

8281
<Media>
83-
<div class="small">
84-
<span class="light:sl-hidden">
85-
![View transition image hides searchbox](@/assets/hide-and-seek/_unhidden-dark.png)
86-
</span>
87-
<span class="dark:sl-hidden">
88-
![iew transition image hides searchbox](@/assets/hide-and-seek/_unhidden-light.png)
89-
</span>
90-
</div>
91-
<p slot="caption">Header is obscured by text</p>
82+
<div class="small">
83+
<span class="light:sl-hidden">
84+
![View transition image hides
85+
searchbox](@/assets/hide-and-seek/_unhidden-dark.png)
86+
</span>
87+
<span class="dark:sl-hidden">
88+
![iew transition image hides
89+
searchbox](@/assets/hide-and-seek/_unhidden-light.png)
90+
</span>
91+
</div>
92+
<p slot="caption">Header is obscured by text</p>
9293
</Media>
9394

9495
<style>{`
@@ -125,6 +126,7 @@ mobile-starlight-toc nav {
125126
The first rule targets the header which holds the searchbox. The second line targets the page navigation of the mobile view.
126127

127128
The paint order for old images in the view transition layer mirrors the paint order of their corresponding elements in the DOM. Images exclusive to the new page [are painted after that](/basics/pseudos/#rendering-pseudo-elements). If you need precise control over the stacking order of the pseudo-elements within the view transition layer, you can adjust it by assigning a `z-index` to the group pseudo-element. This is not needed for our Starlight example, as the header renders after the main area and thus the header's pseudo-element will render above that of the main area. But if you are looking for an example, here it is:
129+
128130
```css
129131
::view-transition-group(header) {
130132
z-index: 1;
@@ -136,18 +138,19 @@ The paint order for old images in the view transition layer mirrors the paint or
136138
Another approach is to clip view transition images at their corresponding image pair or transition group. For example, this site uses a sliding view transition animation for the main content. Without specific adjustments, this animation would cause the main content to overlap the sidebar on the left and the in-page navigation on the right:
137139

138140
<div class="large">
139-
<Media>
140-
<span class="light:sl-hidden">
141-
![View transition images for main content overlap with
142-
sidebars](@/assets/hide-and-seek/_main-unhidden-dark.png)
143-
</span>
144-
<span class="dark:sl-hidden">
145-
![View transition images for main content overlap with
146-
sidebars](@/assets/hide-and-seek/_main-unhidden-light.png)
147-
</span>
148-
<p slot="caption">View transition images for main content overlap with
149-
sidebars</p>
150-
</Media>
141+
<Media>
142+
<span class="light:sl-hidden">
143+
![View transition images for main content overlap with
144+
sidebars](@/assets/hide-and-seek/_main-unhidden-dark.png)
145+
</span>
146+
<span class="dark:sl-hidden">
147+
![View transition images for main content overlap with
148+
sidebars](@/assets/hide-and-seek/_main-unhidden-light.png)
149+
</span>
150+
<p slot="caption">
151+
View transition images for main content overlap with sidebars
152+
</p>
153+
</Media>
151154
</div>
152155

153156
This overlap can be avoided by clipping the old and new images at the edges of their image pair:
@@ -163,25 +166,27 @@ Activating the Inspection Chamber (and temporarily disabling most of the view tr
163166
Since the main content areas occupy the same position on both the old and new pages, the browser's default animation for the `main` transition group has no effect during the transition. The group doesn't morph or move, it remains stationary. The combined effect with the clipping is that the view transition of the main content section seems to slide below the sidebars.
164167

165168
<div class="large">
166-
<Media>
167-
<span class="light:sl-hidden">
168-
![View transition images for main content get clipped to their original
169-
position](@/assets/hide-and-seek/_main-hidden-dark.png)
170-
</span>
171-
<span class="dark:sl-hidden">
172-
![View transition images for main content get clipped to their original
173-
position](@/assets/hide-and-seek/_main-hidden-light.png)
174-
</span>
175-
<p slot="caption">View transition images for main content get clipped to their original
176-
position</p>
169+
<Media>
170+
<span class="light:sl-hidden">
171+
![View transition images for main content get clipped to their original
172+
position](@/assets/hide-and-seek/_main-hidden-dark.png)
173+
</span>
174+
<span class="dark:sl-hidden">
175+
![View transition images for main content get clipped to their original
176+
position](@/assets/hide-and-seek/_main-hidden-light.png)
177+
</span>
178+
<p slot="caption">
179+
View transition images for main content get clipped to their original
180+
position
181+
</p>
177182
</Media>
178183
</div>
179184

180185
### Clipping at the Group or Image Pair?
181186

182187
The browser’s user agent stylesheet aligns the `::view-transition-image-pair(...)` with its `::view-transition-transition-group(...)` in terms of geometry and transform properties. This means you can use either pseudo-element for clipping purposes, and initially, they will produce the same result.
183188

184-
Since these pseudo-elements are fully customizable through CSS, you can alter their properties as needed. You could resize them, add margins, or tweak other styles to create unique visual effects. For instance, you could retain the default morph animation on the transition group while applying a custom animation to the image-pair for clipping.
189+
Since these pseudo-elements are fully customizable through CSS, you can alter their properties as needed. You could resize them, add margins, or tweak other styles to create unique visual effects. For instance, you could retain the default morph animation on the transition group while applying a custom animation to the image-pair for clipping.
185190

186191
The latest pseudo-element addition to the View Transition API points to something new: for _nested_ view transition groups, the pseudo-element tree now includes a `view-transition-group-children` element designed specifically for clipping children. See the next section.
187192

@@ -214,13 +219,12 @@ Clipping at the `::view-transition-group-children` element respects the border.
214219
></iframe>
215220
</SidePicture>
216221

222+
_Scoped_ view transitions are still a bit further in the future. Once available, they will also enable clipping view transition animations on any DOM element. Early implementations really worked well for clipping. In contrast to nested view transition groups, the elements used to move behind the scrollbars.
217223

224+
Current implementations of scoped view transitions do not seem to help much for clipping. Have to revisit this examples shortly.
218225

219-
_Scoped_ view transitions are still a bit further in the future. Once available, they will also enable clipping view transition animations on any DOM element. They really work well for clipping. In contrast to nested view transition groups, the elements move behind the scrollbars.
220226

221-
Scoped transitions also arrived in Chrome Canary 136. In the early versions, there had been an issue when the code was included in an iframe. If the example to the left seems to be broken, here is a [direct link](/basics/hide-and-seek/list-scoped/).
222-
223-
So until _nested_ view transition groups and _scoped_ view transitions are supported by all major browsers, we have to play some tricks to simulate the clipping. See the next section on how to do that.
227+
So until _nested_ view transition groups and _scoped_ view transitions are supported by all major browsers, we have to play some tricks to simulate the clipping. See the next section on how to do that.
224228

225229
## Taming Images of Clipped Elements
226230

@@ -240,13 +244,11 @@ This behavior can work well for elements that naturally feel like they should ov
240244

241245
If unwanted images appear during view transitions, there are currently two main ways to prevent this (with nested view transition groups as a third option when they become available):
242246

243-
244247
- **Dynamically Set View Transition Names:**
245-
Modify the view-transition-name property just before the transition starts. This allows you to selectively include or exclude elements from the transition, ensuring only the intended elements participate.
248+
Modify the view-transition-name property just before the transition starts. This allows you to selectively include or exclude elements from the transition, ensuring only the intended elements participate.
246249

247250
- **Obscure Images with Overlapping Elements:**
248-
Place other pseudo-elements above the images you want to hide. These elements can be part of the view transition and strategically positioned to block unwanted visuals during the transition.
249-
251+
Place other pseudo-elements above the images you want to hide. These elements can be part of the view transition and strategically positioned to block unwanted visuals during the transition.
250252

251253
### Dynamically Named View Transition
252254

@@ -318,6 +320,7 @@ Such effects can be prevented by just setting the `z-index` property on the DOM
318320
Stencils do not need to be simple rectangles. Especially when you want to cover all four sides of an area the following trick can come in handy: Here the stencil is a copy of the clipped area with some surrounding elements, featuring a hole in the middle to reveal the original elements.
319321

320322
Stencils don't have to be limited to basic rectangles. Especially when covering all four sides of an area, one approach is to create a stencil that mimics the clipped content, including adjacent elements, but with a cut-out section in the middle. This design allows the stencil to mask unwanted areas while revealing the desired content through the central "window."
323+
321324
</SidePicture>
322325

323326
<SidePicture>
@@ -329,13 +332,10 @@ Stencils don't have to be limited to basic rectangles. Especially when covering
329332
src="/basics/hide-and-seek/list/"
330333
></iframe>
331334

332-
333-
In our scrollable list example, we overlay the list with a stencil that covers both the list and the surrounding area. On top of the stencil is a copy of the list and a button. To ensure users interact with the original list beneath, we apply `pointer-events: none` to the stencil.
334-
335+
In our scrollable list example, we overlay the list with a stencil that covers both the list and the surrounding area. On top of the stencil is a copy of the list and a button. To ensure users interact with the original list beneath, we apply `pointer-events: none` to the stencil.
335336

336337
The stencil has a transparent, rectangular cut-out aligned with the visible portion of the scrollable list, excluding the scrollbar. This effect is achieved by using a mask image on the stencil. As a result, only the list items within the scrollable area remain visible through the cut-out, while all other elements, including the original scrollbar, are hidden. JavaScript keeps the two scrollbars synchronized.
337338

338-
339339
The stencil gets a view transition name assigned to it. During the view transition, the stencil’s pseudo-element appears in front of everything else, as demonstrated when hovering over the orange sketch below.
340340

341341
</SidePicture>

0 commit comments

Comments
 (0)