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

Install with Vite

Add Diorama to a Vite site with the plugin that finds your effects and writes their types.

View as Markdown
On this page

The Vite plugin turns every file in src/effects/ into an effect that loads on demand and writes the types of those effects to src/diorama.gen.d.ts. It works with any framework that builds with Vite.

Install the packages

Terminal window
npm install @dioramajs/diorama three
Terminal window
pnpm add @dioramajs/diorama three
Terminal window
yarn add @dioramajs/diorama three
Terminal window
bun add @dioramajs/diorama three

Add the plugin

Add diorama() to the plugins in vite.config.ts.

vite.config.ts
import {
function diorama(options?: DioramaPluginOptions): Plugin

Vite plugin, plugins: [diorama()].

diorama
} from '@dioramajs/diorama/vite'
export default {
plugins: Plugin<any>[]
plugins
: [
function diorama(options?: DioramaPluginOptions): Plugin

Vite plugin, plugins: [diorama()].

diorama
()] }

Start the app

Call start() once in the module every page loads.

src/main.ts
import {
function start(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'
export const
const app: App
app
=
function start(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
()

Put an effect on an image

Add data-dio with an effect name to an element. The ripple effect comes with start().

index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Diorama</title>
<script type="module" src="/src/main.ts"></script>
</head>
<body>
<img
src="/cover.jpg"
width="800"
height="450"
data-dio="ripple"
/>
</body>
</html>

Run the dev server and move the pointer over the image. Rings spread from the pointer, and the image keeps its place in the layout while you scroll.

Plugin options

NameTypeDescription
readonly dir?string

The effects folder, relative to the Vite root. Default 'src/effects'.

readonly types?string | false

The types file, relative to the root, or false for none. Default 'src/diorama.gen.d.ts'.