You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: demo/get-animations/index.html
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -52,10 +52,10 @@
52
52
</div>
53
53
<divclass="shell-explanation">
54
54
<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>
56
56
<hr>
57
57
<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>
59
59
<pre><code>const t = document.startViewTransition(() => {
Copy file name to clipboardExpand all lines: demo/measure/index.html
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -51,8 +51,8 @@
51
51
</div>
52
52
</div>
53
53
<divclass="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>
56
56
<hr>
57
57
<h3>The Code</h3>
58
58
<p>The demo triggers a View Transition on click and logs the geometry of the box group:</p>
Copy file name to clipboardExpand all lines: demo/navigation-types/index.html
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -54,14 +54,15 @@ <h2>Navigation Types</h2>
54
54
<p>Automatically inject <code>from-<name></code> and <code>to-<name></code> View Transition Types based on navigation origin and destination.</p>
55
55
<hr>
56
56
<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>
58
58
<pre><code>const routeMap = {
59
59
"index": "/navigation-types/demo",
60
60
"detail": "/navigation-types/detail/:id",
61
61
"about": "/navigation-types/about"
62
62
};
63
63
64
64
useAutoTypes(routeMap);</code></pre>
65
+
<p>This will set the <code>from-<name></code> and <code>to-<name></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>
65
66
<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>
Copy file name to clipboardExpand all lines: demo/optimize/index.html
+4-3Lines changed: 4 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -50,18 +50,19 @@
50
50
</div>
51
51
</div>
52
52
<divclass="shell-explanation">
53
-
<h2>Optimize</h2>
53
+
<h2>Animations: Optimize</h2>
54
54
<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>
55
55
<hr>
56
56
<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>
<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>
65
66
<hr>
66
67
<h3>Functions Used</h3>
67
68
<p>This demo uses <code>optimizeGroupAnimations</code> to replace width/height animations with performant transform-based animations:</p>
<p>Once the View Transition is paused, use the slider to scrub through the animation, or click resume to let it finish.</p>
69
70
<hr>
70
71
<h3>Functions Used</h3>
71
72
<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>
72
73
<pre><code>import { pause, resume, scrub } from "view-transitions-toolkit/playback-control";
73
74
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>
77
78
</div>
78
79
<footerclass="shell-footer desktop-only">
79
80
<p><code>view-transitions-toolkit</code> is a a Chrome DevRel Project.<br>
Copy file name to clipboardExpand all lines: demo/scroll-driven-view-transition/index.html
+11-8Lines changed: 11 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -50,11 +50,11 @@
50
50
</div>
51
51
</div>
52
52
<divclass="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>
55
55
<hr>
56
56
<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>
<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>
69
75
<hr>
70
76
<h3>Functions Used</h3>
71
77
<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>
72
78
<pre><code>import { trackActiveViewTransition } from "view-transitions-toolkit/track-active-view-transition";
73
-
import { pause, scrub } from "view-transitions-toolkit/playback-control";
0 commit comments