Diorama

Made for a big screen.

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.

GitHub

DioramaDocs

Use without a build step

Start Diorama on a plain HTML page, Webflow or Tilda with one script tag from a CDN.

View as Markdown
On this page

The CDN build starts the app on its own with the image effects and page transitions, and loads three.js in separate chunks after the first paint.

Add the script

index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Diorama</title>
<script
type="module"
src="https://cdn.jsdelivr.net/npm/@dioramajs/diorama/dist/cdn/auto.js"
></script>
</head>
<body>
<img
src="/cover.jpg"
width="800"
height="450"
data-dio="ripple"
/>
</body>
</html>

If the page loads GSAP from a CDN, window.gsap and window.ScrollTrigger are picked up without code.

Pass options

Options of start() go in window.diorama, set before the script tag.

<script>
window.diorama = { canvas: 'behind' }
</script>

Set window.diorama = { manual: true } to call start() yourself.

Write your own effect

Your effect is a module that imports effect from the same address, so the page has one copy of Diorama.

fx/brighten.js
import { effect } from 'https://cdn.jsdelivr.net/npm/@dioramajs/diorama/dist/cdn/auto.js'
export default effect({ strength: 1 }, ({ surface, u }) => {
surface.color((color) => color.mul(u.strength.add(1)))
})

Register it in the options under the name you use in markup.

<script>
window.diorama = { effects: { brighten: () => import('/fx/brighten.js') } }
</script>
<img
src="/cover.jpg"
data-dio="brighten"
data-dio-strength="2"
/>

To keep a folder of effects, let the CLI write the registry for you. With a .js output, dioramajs gen writes a module that imports every effect file of the folder.

Terminal window
npx dioramajs gen --dir fx --out fx/registry.js
Terminal window
pnpm exec dioramajs gen --dir fx --out fx/registry.js
Terminal window
yarn dioramajs gen --dir fx --out fx/registry.js
Terminal window
bunx dioramajs gen --dir fx --out fx/registry.js

See the CLI for the other formats.