data-transition
Declarative View Transitions API integration. Marks elements that morph, slide, or fade during state changes.
Overview
The data-transition attribute marks elements that participate in View Transitions. Unlike data-effect (ambient animation), data-transition describes state-change moments — navigation, DOM swaps, route changes.
VB auto-assigns view-transition-name and optional view-transition-class so the browser's View Transition API handles the animation.
Mental model
Two attribute systems, two purposes:
| Intent | Attribute | When |
|---|---|---|
| Ambient animation | data-effect | Scroll, hover, load |
| State change | data-transition | DOM updates, navigation |
morph
The element morphs between its old and new state. The browser interpolates position, size, and appearance. Ideal for images, cards, and shared elements across views.
VB assigns view-transition-name: morph-{uid} automatically. Use id for stable names or let VB generate one.
slide
Page-level slide animation. The old content slides out while new content slides in.
fade
Explicit crossfade without position morphing. Good for content areas that shouldn't move.
scale
Scale-down/scale-up swap effect.
stagger
Children get individual view-transition-name values so they can reorder, add, or remove with staggered timing.
none
Instant swap with no animation. Opt out a specific section from the page-level transition.
VB.swap()
Wrap any DOM mutation in a View Transition. Falls back gracefully when the API isn't supported.
Custom transitions
Register custom transition types via VB.transition().
Combining with effects
Both systems compose on the same element. data-effect handles ambient animation while data-transition handles state changes.
Browser support
View Transitions require Chrome 111+ or Safari 18+. In unsupported browsers, VB.swap() falls back to calling the update function directly — the DOM change happens instantly, no error.
API reference
| Transition | CSS Class | Description |
|---|---|---|
morph | (default crossfade) | Position + size + appearance morph between states. |
slide | slide-left | Horizontal slide out/in. |
fade | fade | Crossfade without position interpolation. |
scale | scale | Scale-down/scale-up swap. |
stagger | fade | Children get individual names for list reorder transitions. |
none | none | Instant swap, no animation. |
| JS Method | Signature | Description |
|---|---|---|
VB.transition() | (name, handler) => void | Register a custom transition type. |
VB.swap() | (update) => ViewTransition? | Wrap DOM mutations in a View Transition. |
VB.uid() | (el) => string | Stable unique ID for view-transition-name generation. |