Bramus! Profile picture
8 Jun, 11 tweets, 6 min read
๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ

`document.documentTransition` is a new experimental API in @ChromiumDev that allows you to create transitions between two different visual frames.

๐Ÿ”— chromestatus.com/feature/519300โ€ฆ

Let's dig in โ€ฆ ๐Ÿงต
@ChromiumDev In this example you see the API transition between the frame with the avatar and the frame with the info modal. The transition โ€” including "slide up" animation โ€” is handled by the API/browser.

๐Ÿ”— codepen.io/bramus/pen/rNjโ€ฆ

This is called a Root Transition.
@ChromiumDev To make it work, you need to perform 3 steps:

1. Capture the begin frame
2. Make UI changes (which are not rendered on screen)
3. Transition to the new (target) frame
@ChromiumDev Here's some code:

```
const transition = async () => {
// Capture
await document.documentTransition.prepare({
rootTransition: "cover-up",
});

// Update UI
document.body.classList.add('show-modal');

// Transition
document.documentTransition.start();
};
``` Image
@ChromiumDev Allowed `rootTransition` values:

- reveal-x: old content slides from center in direction x, revealing new content.
- cover-x: new content slides from an edge in direction x, covering old content.
- explode
- implode

See this video for a visual demo:
@ChromiumDev What's pretty cool about this API is that is also supports Shared Element Transitions.

It allows you to mark elements that exist in both frames.

While the Root Transition runs, Shared Elements โ€” here the avatar โ€” are transitioned independently.

๐Ÿ”— codepen.io/bramus/pen/VwPโ€ฆ
@ChromiumDev To use Shared Elements, you need to pass each into `.prepare()` and `.start()`:

```
await document.documentTransition.prepare({
โ€ฆ
sharedElements: [
$elInStartFrame,
]
});

โ€ฆ

document.documentTransition.start({
sharedElements: [
$elInTargetFrame,
]
});
``` Image
@ChromiumDev You can pass in as many as you want, as long as they both have the same number of entries. They're matched against each other using their index.
@ChromiumDev For Shared Element Transitions to work though you need to enable CSS Paint Containment on them:

```css
.elInStartFrame, .elInTargetFrame, {
contain: paint;
}
``` Image
@ChromiumDev ๐Ÿ‘จโ€๐Ÿ”ฌ To use this API today, enable the `#document-transition` flag in your Chromium-based browser (Chromium 89+), or register your page for the Origin Trial once it's up on developer.chrome.com/origintrials/ (Chromium 92+)

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with Bramus!

Bramus! Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(