Skip to content
/greyscale
No. 04 · Make it move right · Chapter 1 of 3

Two nodes, one identity

Murat Alpay · · 4 min read
Free

A card opens into a detail view, and it should look like one object growing. The instinct is to build it that way too: take the card's element and fly it into the dialog.

Keep that picture and you end up fighting the animation, and often ship a crossfade wearing a spring. The picture I use instead is two elements with one name.

#Two elements, one name

The card in the list and the panel in the dialog are different elements. Each is rendered where it belongs, in its own state. Give both the same id, and the animation measures where the first one was and where the second one is, then animates the difference with transforms. It's close to FLIP: first, last, invert, play.

Nothing travels through the DOM. You don't move the card into a portal or copy its position by hand. While the dialog is open, the card in the list can be gone entirely, and its slot is just a slot.

Card in the listRendered
Panel in the dialogNot rendered
Shared idproject-card-42

Closed. The list renders the card with the id project-card-42. The dialog panel is not rendered.

Two nodes share one id. The panel morphs; the text, close button and backdrop fade on their own.

The animation library I use calls this id layoutId. The browser's View Transitions API has the same idea under view-transition-name. Either way, the identity is the name, not the DOM node.

If I have a transition that moves an element between containers, or animates its width and height by hand, I render the two states as two elements and give them one id.

#One id per story

A layout id is global unless you scope it. If two unrelated components happen to use the same id, the animation can treat them as one story. The indicator under one tab row jumps into another, and the first row is left without one.

When two elements share an id on purpose and are on screen together, they can crossfade. That's a feature. Accidental identity is the bug.

So name the relationship, not the shape. project-card-42 is a story. dot is an invitation to regret.

View
Sort
underlineOne underline. Sort has lost its own.

Both rows use the id underline, so there is one underline. It sits in the view row; the Sort row has none.

Two tab rows on one page. Pick a tab in either row.

Several shared transitions at once are fine. Give each one a stable id, or scope a repeated component so every instance gets its own. A prefix made from the instance's own id works anywhere; some libraries also have a group wrapper for it.

I search the code for layout ids, and rename any that names a shape, like pill or underline, after the two things it connects, or scope it per instance.

#Halfway, everything inside is scaled

Position and size are only half of it. A small card can become a full dialog and still feel like one object, but the details have to survive the morph.

During the animation, the element already has its final size. The animation scales it down to look like where it came from, then lets the scale go. A radius set in a class gets scaled with everything else, so the corners shrink and squash, then grow back. Shadows stretch the same way. Text inside the box gets squashed too.

Halfway through the morphDashed: final size
Visible corner
10 × 8px
Title
Squashed
The radius sits in a class, so it scales with the box. So does the text.

The radius sits in a class, so it scales with the box. So does the text. Visible corner: 10 × 8px. Title: squashed.

Example values. One frame from the middle of the morph: the box at its final size, scaled down.

Set the radius and the shadow where the animation can see them, in the props it animates, and it corrects them for the scale on every frame. If the corner snaps while the body morphs, the object looks like it changed species halfway through. The animation didn't fail there. The identity did.

For text, give the title its own id so it morphs on its own. Keep the description out of the box and fade it in separately.

I slow a shared transition to a tenth of its speed in the browser's animation tools and watch only the corners, the shadow and the text, not the box.

#Give each part one job

Exit animations and shared layout can run together. The question is what leaves, and how.

If the shared element needs to go back to where it came from when the dialog closes, the exit handling keeps the outgoing node mounted long enough for that. The close button, the description and the backdrop get their own keys and their own fades.

Layout carries continuity. Opacity carries appearance. A backdrop can disappear without asking the object itself to dissolve.

I list every part of the moving element and write "layout" or "opacity" next to each. Anything marked opacity comes out of the shared element and gets its own key.

#When this is overkill

Shared layout isn't free. It costs attention, code and bundle size. Use it when the relationship is the point: a card becomes a detail view, an image becomes a lightbox, two items trade places.

A tab you hit all day doesn't need a pill that chases you. The first few times it's nice. After that it's a delay between your click and the answer. Frequency is still a design input.

Shared idinbox-tab-pill
Switches so far0
The pill slides to the new tab. Rare enough to enjoy.

Used now and then: the pill has a shared id and slides to the new tab.

The same tabs for two kinds of use. Click through them in each.

If the two states aren't the same thing, don't give them one id. A list and a settings page that happen to share a header aren't one object. A plain fade is more honest there.

I pick the shared transition people trigger most and turn it off for a week, to see if I miss it.

#What I'm trying next

Next I want to try the same idea across a page change, where the two nodes live on different pages and the browser holds the name. I don't know yet whether the corner and text problems look the same there, or whether the fixes carry over.

Two nodes, one identity, or a fade.

Subscribe

Issue 04 · Make it move right