Skip to content

Commit 8fc2701

Browse files
committed
Update demo descriptions
1 parent 58b3fd2 commit 8fc2701

10 files changed

Lines changed: 41 additions & 35 deletions

File tree

demo/feature-detection/scripts.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { supports } from "../js/feature-detection.js";
22

33
const labels = {
4-
sameDocument: "Same-Document View Transitions (<code>document.startViewTransition</code>)",
4+
sameDocument:
5+
"Same-Document View Transitions (<code>document.startViewTransition</code>)",
56
types: "View Transition Types (<code>transition.types</code>)",
6-
crossDocument: "Cross-Document View Transitions (<code>@view-transition</code> rule)",
7-
elementScoped: "Element-Scoped View Transitions (<code>Element.startViewTransition</code>)",
8-
activeViewTransition: "Active View Transition tracking (<code>document.activeViewTransition</code>)",
7+
crossDocument:
8+
"Cross-Document View Transitions (<code>@view-transition</code> rule)",
9+
elementScoped:
10+
"Element-Scoped View Transitions (<code>Element.startViewTransition</code>)",
11+
activeViewTransition:
12+
"Active View Transition tracking (<code>document.activeViewTransition</code>)",
913
};
1014

1115
const statusLights = document.getElementById("status-lights");
@@ -20,8 +24,4 @@ statusLights.innerHTML = Object.entries(supports)
2024
)
2125
.join("");
2226

23-
document.getElementById("output").innerText = JSON.stringify(
24-
supports,
25-
null,
26-
4,
27-
);
27+
document.getElementById("output").innerText = JSON.stringify(supports, null, 4);

demo/get-animations/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@
5252
</div>
5353
<div class="shell-explanation">
5454
<h2>Animations: getAnimations</h2>
55-
<p>Demonstrates the <code>getAnimations</code> function from the toolkit to inspect View Transition animations.</p>
55+
<p>The <code>getAnimations</code> function from the toolkit is a wrapper around <code>document.getAnimations()</code> that returns only the animations related to View Transitions. You can further filter the animations by providing a <code>view-transition-name</code> and/or a <code>ViewTransitionPart</code>.</p>
5656
<hr>
5757
<h3>The Code</h3>
58-
<p>The demo triggers a View Transition, randomizes layout, and calls <code>getAnimations</code>:</p>
58+
<p>The demo triggers a View Transition, randomizes layout, and calls <code>getAnimations</code> to get the animations of the element with the <code>view-transition-name: box</code>:</p>
5959
<pre><code>const t = document.startViewTransition(() => {
6060
randomize();
6161
});

demo/measure/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
</div>
5252
</div>
5353
<div class="shell-explanation">
54-
<h2>Measure</h2>
55-
<p>Extract and measure geometry (size and position) of View Transition pseudo-elements using <code>extractGeometry</code>.</p>
54+
<h2>Animations: Measure</h2>
55+
<p>Extract and measure geometry (size and position) of View Transition pseudo-elements using <code>extractGeometry</code>. The result is an object with a <code>before</code> and <code>after</code> property, each containing the geometry of the element. Each geometry object has <code>width</code>, <code>height</code>, <code>top</code>, and <code>left</code> properties.</p>
5656
<hr>
5757
<h3>The Code</h3>
5858
<p>The demo triggers a View Transition on click and logs the geometry of the box group:</p>

demo/navigation-types/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@ <h2>Navigation Types</h2>
5454
<p>Automatically inject <code>from-&lt;name&gt;</code> and <code>to-&lt;name&gt;</code> View Transition Types based on navigation origin and destination.</p>
5555
<hr>
5656
<h3>The Code</h3>
57-
<p>The demo uses <code>useAutoTypes</code> with a route map to determine types during navigation:</p>
57+
<p>The demo uses <code>useAutoTypes</code> with a route map to determine types during navigation. A route map is a mapping of route names to their corresponding URL patterns. In this demo, we use the following route map:</p>
5858
<pre><code>const routeMap = {
5959
"index": "/navigation-types/demo",
6060
"detail": "/navigation-types/detail/:id",
6161
"about": "/navigation-types/about"
6262
};
6363

6464
useAutoTypes(routeMap);</code></pre>
65+
<p>This will set the <code>from-&lt;name&gt;</code> and <code>to-&lt;name&gt;</code> types on the active <code>ViewTransition</code> based on the navigation origin and destination. For example, if you navigate from the index page to a detail page, the <code>from-index</code> and <code>to-detail</code> types will be set on the active <code>ViewTransition</code>.</p>
6566
<p>In your CSS, you can then target these types using the <code>:active-view-transition-type</code> pseudo-class to style elements conditionally:</p>
6667
<pre><code>:active-view-transition-type(from-index) .from { background-color: #f0f0f0; }
6768
:active-view-transition-type(to-index) .to { background-color: #f0f0f0; }

demo/optimize/demo.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</head>
1515
<body>
1616
<div class="box" id="box-normal">REGULAR</div>
17-
<div class="box" id="box-flip">FLIP</div>
17+
<div class="box" id="box-optimized">OPTIMIZED</div>
1818

1919
<div class="debug" id="debug"></div>
2020
</body>

demo/optimize/index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,19 @@
5050
</div>
5151
</div>
5252
<div class="shell-explanation">
53-
<h2>Optimize</h2>
53+
<h2>Animations: Optimize</h2>
5454
<p>Optimize <code>::view-transition-group</code> animations using performant <code>transform</code>-based animations instead of <code>width</code> and <code>height</code> changes.</p>
5555
<hr>
5656
<h3>The Code</h3>
57-
<p>The demo triggers a View Transition on click and optimizes the "box-flip" group:</p>
57+
<p>When you click the page, the demo triggers a View Transition and optimizes the "box-optimized" group. This optimized animation is a transform-based animation that animates the <code>scale</code> property instead of <code>width</code> and <code>height</code>.</p>
5858
<pre><code>document.body.addEventListener("click", async (e) => {
5959
const t = document.startViewTransition(() => {
6060
mutateTheDOM();
6161
});
6262
await t.ready;
63-
optimizeGroupAnimations(t, "box-flip");
63+
optimizeGroupAnimations(t, "box-optimized");
6464
});</code></pre>
65+
<p>Because this optimized animation runs on the compositor, it will not be subject to jank, unlike the default <code>width</code>/<code>height</code> animations.</p>
6566
<hr>
6667
<h3>Functions Used</h3>
6768
<p>This demo uses <code>optimizeGroupAnimations</code> to replace width/height animations with performant transform-based animations:</p>

demo/optimize/scripts.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ document.body.addEventListener("click", async (e) => {
4343
});
4444
await t.ready;
4545

46-
optimizeGroupAnimations(t, "box-flip");
46+
optimizeGroupAnimations(t, "box-optimized");
4747

4848
// Dump the generated keyframes
4949
const animations = getAnimations(t, "*", ViewTransitionPart.Group);
5050
const animationKeyframes = {
5151
regular: animations[0].effect.getKeyframes(),
52-
flip: animations[1].effect.getKeyframes(),
52+
optimized: animations[1].effect.getKeyframes(),
5353
};
5454
document.getElementById("debug").innerText = JSON.stringify(
5555
animationKeyframes,

demo/optimize/styles.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#box-normal {
1515
view-transition-name: box-normal;
1616
}
17-
#box-flip {
18-
view-transition-name: box-flip;
17+
#box-optimized {
18+
view-transition-name: box-optimized;
1919
}
2020

2121
#debug {

demo/playback-control/index.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@
5151
</div>
5252
<div class="shell-explanation">
5353
<h2>Playback Control</h2>
54-
<p>Control the playback of a View Transition. Use utilities to pause, resume, or scrub all animations simultaneously.</p>
54+
<p>Control the playback of a View Transition. Use utilities to pause, resume, or scrub all animations linked to a View Transition simultaneously.</p>
5555
<hr>
5656
<h3>The Code</h3>
57-
<p>The demo binds click and input events to <code>pause</code>, <code>resume</code>, and <code>scrub</code> functions:</p>
57+
<p>The demo binds click and input events to the <code>pause</code>, <code>resume</code>, and <code>scrub</code> functions:</p>
5858
<pre><code>document.getElementById("pause").addEventListener("click", () => {
5959
pause(t);
6060
});
@@ -66,14 +66,15 @@ <h3>The Code</h3>
6666
document.getElementById("scrub").addEventListener("input", (e) => {
6767
scrub(t, e.target.value);
6868
});</code></pre>
69+
<p>Once the View Transition is paused, use the slider to scrub through the animation, or click resume to let it finish.</p>
6970
<hr>
7071
<h3>Functions Used</h3>
7172
<p>This demo uses <code>pause</code>, <code>resume</code>, and <code>scrub</code> to synchronize View Transition playback with a range slider or custom timeline:</p>
7273
<pre><code>import { pause, resume, scrub } from "view-transitions-toolkit/playback-control";
7374

74-
pause(t); // Pauses all VT animations
75-
resume(t); // Resumes all VT animations
76-
scrub(t, position); // Sets animations to 50% playback</code></pre>
75+
pause(t); // Pauses all animations linked to a View Transition
76+
resume(t); // Resumes all animations linked to a View Transition
77+
scrub(t, 0.5); // Sets animations to 50% playback</code></pre>
7778
</div>
7879
<footer class="shell-footer desktop-only">
7980
<p><code>view-transitions-toolkit</code> is a a Chrome DevRel Project.<br>

demo/scroll-driven-view-transition/index.html

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@
5050
</div>
5151
</div>
5252
<div class="shell-explanation">
53-
<h2>Scroll-Driven</h2>
54-
<p>Connect view transitions to scroll animations. Create fluid, progressive scene changes driven by the user's viewport.</p>
53+
<h2>Scroll-Driven View Transition</h2>
54+
<p>When scrolling the page, the header card will toggle between the large and small state. This is acthieve by starting a View Transition that is immediately paused and then scrubbed based on the scroll position.</p>
5555
<hr>
5656
<h3>The Code</h3>
57-
<p>The demo starts a View Transition and synchronizes its playback with page scrolling:</p>
57+
<p>Between two scroll positions a View Transition is started and, once started, immediately paused and scrubbed based on the scroll position.</p>
5858
<pre><code>const startViewTransition = async () => {
5959
document.startViewTransition(() => {
6060
document.querySelector(".card").classList.toggle("small");
@@ -66,15 +66,18 @@ <h3>The Code</h3>
6666
const updateAnimations = () => {
6767
scrub(document.activeViewTransition, scrollProgress);
6868
};</code></pre>
69+
<p>When scrolling back the animations need to play in reverse. This is achieved by reversing the animations and scrubbing from 1 to 0.</p>
70+
<pre><code>if (isReverse) {
71+
for (const anim of getAnimations(document.activeViewTransition)) {
72+
anim.reverse();
73+
}
74+
}</code></pre>
6975
<hr>
7076
<h3>Functions Used</h3>
7177
<p>This demo uses <code>trackActiveViewTransition</code>, <code>getAnimations</code>, and utilities like <code>pause</code> / <code>scrub</code> to synchronize a View Transition with scroll state:</p>
7278
<pre><code>import { trackActiveViewTransition } from "view-transitions-toolkit/track-active-view-transition";
73-
import { pause, scrub } from "view-transitions-toolkit/playback-control";
74-
75-
trackActiveViewTransition();
76-
pause(document.activeViewTransition);
77-
scrub(document.activeViewTransition, scrollProgress);</code></pre>
79+
import { getAnimations } from "view-transitions-toolkit/animations";
80+
import { pause, scrub } from "view-transitions-toolkit/playback-control";</code></pre>
7881
</div>
7982
<footer class="shell-footer desktop-only">
8083
<p><code>view-transitions-toolkit</code> is a a Chrome DevRel Project.<br>

0 commit comments

Comments
 (0)