Introducing view-transitions-toolkit, a collection of utility functions to more easily work with View Transitions.

Screenshot of the View Transitions Toolkit homepage

~

In my work with View Transitions over the last several years, I’ve published everything from deep-dive articles, demos, and announcement videos at Google I/O. I’ve also done some more experimental things with it, such as optimizing the keyframes or driving a View Transition by scroll.

To turn the lessons from these scattered experiments into something more reusable for both you and me, I’ve bundled the most frequent code patterns into a dedicated package: view-transitions-toolkit.

~

The view-transitions-toolkit

view-transitions-toolkit is a collection of small, focused helper functions for use with View Transitions. They fill in some of the gaps to making advanced patterns much easier to implement.

  • Feature Detection: Get information about whether certain View Transitions sub-features are supported.
  • Shim Support: Shim support for document.activeViewTransition.
  • Animations: Utilities for extracting, measuring, and optimizing animations.
  • Transition Playback Control: Pause, Resume, or Scrub the playback of a View Transition.
  • Automatic Page Navigation Types: Automatically inject View Transition Types based on navigation origin/destination.

The goal of the project is to provide these utilities so you don’t have to reinvent the wheel every time you want to do something slightly advanced with View Transitions.

~

Getting Started

Using the toolkit is incredibly simple. First, install it from npm:

npm i view-transitions-toolkit

Then, you can import the modules you need and use their functions. Optimizing the keyframes of a View Transition group for example is a simple one-liner:

import { optimizeGroupAnimations, OPTIMIZATION_STRATEGY } from "view-transitions-toolkit/animations";

const t = document.startViewTransition(() => { … });
await t.ready;

// Optimize all Group Animations using the default SCALE strategy
optimizeGroupAnimations(t, "*");

// Optimize only the `::view-transition-group(box-flip)` animation using the SLIDE strategy
optimizeGroupAnimations(t, "box-flip", OPTIMIZATION_STRATEGY.SLIDE);

I won’t go into details here, as all features are documented in the docs folder of the repo.

~

Demos

The project also comes with a public website that not only gives you the basic info, but also comes with a bunch of demos: https://chrome.dev/view-transitions-toolkit/.

Screenshot of the optimize() demo

The source of the demos is included in the repository as well.

~

Go check it out

~

Spread the word

Feel free to reshare one of the following posts on social media to help spread the word:

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Unless noted otherwise, the contents of this post are licensed under the Creative Commons Attribution 4.0 License and code samples are licensed under the MIT License

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.