This site is one 3D scene, built for a computer: a wide window and a mouse. Open dioramajs.dev on a desktop or a laptop to see it.This site is one 3D scene, built for a wide window. Make this one wider, or open dioramajs.dev on a larger screen.
A flight moves the layer of an element from one page to the element with the same key on the next page. The canvas stays alive between pages, so the same picture moves, resizes and recrops on its way.
Give both elements a key
Put the same data-dio-key on the thumbnail in the list and on the cover of the project page.
work.html
<ahref="/work/aurora">
<img
src="/img/aurora-thumb.avif"
data-dio="image"
data-dio-key="aurora"
/>
</a>
work/aurora.html
<img
src="/img/aurora-cover.avif"
data-dio="image ripple"
data-dio-key="aurora"
/>
Navigate without a reload
A flight needs the app to survive navigation, so the page must change without a full reload.
Wrap your own swap of the page in transition(). It takes a snapshot of the keyed elements, runs the swap and flies them to their partners.
src/main.ts
import{
functionstart(options?:StartOptions):App
Starts Diorama on the page and returns the app at once. It finishes starting in the
background. A second call returns the same app, so a re-run module doesn't make another.
Calls app.transition if the plugin is running, otherwise runs swap once and returns a
settled 'skipped' transition. Safe for routers that navigate before app.start() resolves.
transition}from'@dioramajs/diorama'
exportconst
const app:App
app=
functionstart(options?:StartOptions):App
Starts Diorama on the page and returns the app at once. It finishes starting in the
background. A second call returns the same app, so a re-run module doesn't make another.
import { start } from '@dioramajs/diorama'
export const app = start()
start()
asyncfunction
functiongo(url:string):Promise<void>
go(
url: string
url:string):
interfacePromise<T>
Represents the completion of an asynchronous operation
The parseFromString() method of the DOMParser interface parses an input containing either HTML or XML, returning a Document with the type given in the contentType property.
Calls app.transition if the plugin is running, otherwise runs swap once and returns a
settled 'skipped' transition. Safe for routers that navigate before app.start() resolves.
transition(
const app:App
app,()=>{
var document:Document
window.document returns a reference to the document contained in the window.
The Window.history read-only property returns a reference to the History object, which provides an interface for manipulating the browser session history (pages visited in the tab or frame that the current page is loaded in).
The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.
The read-only target property of the Event interface is a reference to the object onto which the event was dispatched. It is different from Event.currentTarget when the event handler is called during the bubbling or capturing phase of the event.
Element is the most general base class from which all element objects (i.e., objects that represent elements) in a Document inherit. It only has methods and properties common to all kinds of elements. More specific classes inherit from Element.
The closest() method of the Element interface traverses the element and its parents (heading toward the document root) until it finds a node that matches the specified CSS selector.
The preventDefault() method of the Event interface tells the user agent that the event is being explicitly handled, so its default action, such as page scrolling, link navigation, or pasting text, should not be taken.
Add <ClientRouter /> to the layout. Astro swaps the page in place and the keyed elements fly without more code.
src/layouts/Layout.astro
---
import{ ClientRouter }from'astro:transitions'
---
<htmllang="en">
<head>
<ClientRouter/>
</head>
<body>
<slot/>
</body>
</html>
<NuxtPage> without a page transition swaps pages in one render. The keyed elements fly without more code.
The App Router removes the old page and inserts the new one in one commit. The keyed elements fly without more code. With loading.tsx the cover arrives later and the thumbnail waits for it, invisible, for up to 1 second.
The CDN build exports transition() too. Wrap your own swap of the page in it, the same way as with Vite. Turbo Drive swaps the page itself, and keyed elements fly without code.
Tune the flight
A flight takes 0.8 seconds with a cubic in-out ease. Change the defaults for every transition in start().
src/main.ts
import{
functionstart(options?:StartOptions):App
Starts Diorama on the page and returns the app at once. It finishes starting in the
background. A second call returns the same app, so a re-run module doesn't make another.
import { start } from '@dioramajs/diorama'
export const app = start()
start}from'@dioramajs/diorama'
exportconst
const app:App
app=
functionstart(options?:StartOptions):App
Starts Diorama on the page and returns the app at once. It finishes starting in the
background. A second call returns the same app, so a re-run module doesn't make another.
import { start } from '@dioramajs/diorama'
export const app = start()
start({
StartOptions.transitions?:
| boolean
|(
Partial<TransitionsOptions>
&{ readonly cover?: CoverName | CoverOptions; }
)
|undefined
Page transitions by data-dio-key. On by default, false turns them off. cover adds a GL
cover the pages change behind: { cover: 'ink' } or { cover: { name: 'curtain', color } }.
transitions:{
duration?: number |undefined
Seconds. Default 0.8.
duration:0.9}})
While a thumbnail flies, the DOM of its target is hidden with data-dio-state="entering". Use it to hold back a caption until the landing.