orbit
A line of text wraps around a 3D form that turns: a spinning drum, a globe of text, or a tilted ring around a product.
Old quay · August
The lantern night market
Three evenings of paper lanterns, street food and brass bands along the river.
Live preview needs WebGPU or WebGL 2. A night market poster whose words circle a painted paper lantern on a tilted ring, passing behind it and in front of it again.
This example failed to draw.
Usage
Put it on a heading, a short line or a badge; for the ring, a box with an image and a one-line caption. Not img, video, canvas, svg or form fields. start() registers orbit, so the attribute alone puts it on an element. The tabs below are the example above, with the values you set.
To change its code, copy the source into your effects folder; the copy replaces the built-in.
npx @dioramajs/diorama add orbit<section class="ob-hero"> <div class="ob-copy"> <p class="ob-kicker">Old quay · August</p> <h2 class="ob-title">The lantern night market</h2> <p class="ob-line">Three evenings of paper lanterns, street food and brass bands along the river.</p> </div> <figure class="ob-stage" data-dio="orbit" data-dio-style="ring" data-dio-by="auto" data-dio-tilt="16" data-dio-roll="-9" data-dio-radius="0.9" > <img src="/media/orbit/lantern.png"> <figcaption>Night market · Lantern festival ·</figcaption> </figure></section>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.ob-stage', 'orbit', { style: 'ring', by: 'auto', radius: 0.9, tilt: 16, roll: -9, speed: 20, fade: 0.55,})import { start } from '@dioramajs/diorama'import orbit from '@dioramajs/text/orbit'
const app = start()app.attach('.ob-stage', orbit({ style: 'ring', by: 'auto', radius: 0.9, tilt: 16, roll: -9, speed: 20, fade: 0.55,}))Markup it reads
imginside: Images inside are drawn in their place with the form, which passes behind and in front of them.
Page transitions
The form fades with the page. How a flight flies.
Params
Every param is also an attribute, and both app.attach() and the handle take it by name.
| Param | Type | Default | Description |
|---|---|---|---|
stylerebuildsdata-dio-style | 'cylinder' | 'sphere' | 'ring' | 'cylinder' |
|
byrebuildsdata-dio-by | 'scroll' | 'drag' | 'auto' | 'scroll' |
|
radiusdata-dio-radius | number0.1 to 2 | 1 | Radius of the form as a share of half the box width (half its shorter side for sphere). |
tiltdata-dio-tilt | number-60 to 60° | 15 | Lean of the form toward the viewer, so you look down onto it; 0 sees it edge on. |
rolldata-dio-roll | number-45 to 45° | 0 | Sideways lean of the form; positive lifts its right side. |
speeddata-dio-speed | number-90 to 90° | 20 | Turn rate: degrees a second with auto, degrees per 100 px of scroll; 0 holds it. |
repeatdata-dio-repeat | boolean | true | Copies the text to fill the circle all the way around; off shows it once. |
fadedata-dio-fade | number0 to 1 | 0.55 | How much the far side of the form fades with depth; 0 keeps it as solid as the front. |
pausedata-dio-pause | boolean | true | With auto, eases the turn to a stop under the pointer or keyboard focus. |
fpsdata-dio-fps | number10 to 60 | 60 | Most frames a second while it turns by itself.At most low 30 by quality tier. |
colordata-dio-color | color | 'currentColor' | Color of the letters; currentColor or empty keeps the text color. |
Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.
Inputs and frames
It reads delta, height, opacity, reducedMotion, visible, width, x and y
. Draws at a steady rate while it is on screen and stops when it leaves. While the form spins in once, while the page scrolls and the turn catches up, while a drag or its coast lasts; with auto, up to fps while on screen and not paused. How a frame is decided.
Reduced motion and touch
With reduced motion it shows a still frame: motion inputs are zero and time stands still. The form holds still with the front of the text facing the viewer: no scroll turn, no spin and no coast after a drag.
Runs on every device. With by drag, a finger spins the form only where the element has touch-action: pan-y or none, so the page keeps its vertical scroll.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { orbit: { reducedMotion: 'off' } } })Cost and quality
- Download
- 11.4 KB min+gzip the first time a page uses it
- GPU
- Two instanced draws of a bent mesh per letter, one for the near side and one for the far side, with two texture reads per pixel; two more quads per image.
- Memory
- An atlas of the letters at twice their CSS size with mip levels, and a relief map of the same size made when the page is idle.
- Frames
- Draws while on screen
It runs from the low tier up. Each tier changes this: The quality plugin picks the tier for each device.
| Tier | What changes |
|---|---|
low | The letters are rastered at 1 device pixel per CSS pixel instead of 2, and auto turns at up to 30 frames a second. |
Recipes
A headline on a drum that turns with the scroll
The default cylinder style wraps the line around a drum, like a label on a spinning can. The letters in front sit where the heading would be, at its size, and the ones on the far side show mirrored through the gaps, smaller and fainter. With by="scroll", the default, the drum turns as the page scrolls and reads straight on when the heading is in the middle of the screen. Keep the heading on one line with white-space: nowrap: each line of the element becomes a band of its own.
Halden Studio · Brand and motion
Made to be noticed ✦
Identities, launch films and websites for companies that make things by hand.
Live preview needs WebGPU or WebGL 2. A design studio's headline in ivory capitals wrapped around a drum on a dark page, its far side showing mirrored behind the front letters.
This example failed to draw.
<section class="ob-drum"> <p class="ob-drum-kicker">Halden Studio · Brand and motion</p> <h2 class="ob-drum-title" data-dio="orbit" >Made to be noticed ✦</h2> <p class="ob-drum-line">Identities, launch films and websites for companies that make things by hand.</p></section>A globe of text to spin by hand
style="sphere" covers a globe with rows of the text from pole to pole, offset like bricks. With by="drag" the visitor grabs it and flicks it, and it coasts to a stop. Give the element a square box. On touch screens a finger spins it only where the element has touch-action: pan-y or none, so the page still scrolls.
Shipping to 48 countries ·
Free shipping over €80
Every order leaves our workshop in Porto within two days, packed in recycled paper and tracked to your door.
Live preview needs WebGPU or WebGL 2. A shop's shipping note beside a blue globe made of the words Shipping to 48 countries, which you can spin with the pointer.
This example failed to draw.
<section class="ob-ship"> <p class="ob-globe" data-dio="orbit" data-dio-style="sphere" data-dio-by="drag" data-dio-tilt="12" >Shipping to 48 countries ·</p> <div class="ob-ship-copy"> <h3>Free shipping over €80</h3> <p>Every order leaves our workshop in Porto within two days, packed in recycled paper and tracked to your door.</p> </div></section>A slow spinning badge
A short label on a small drum, turning by itself in the corner of a hero, points the way down the page. pause stops it under the pointer and keyboard focus, so a visitor can read it, and it costs no frames while it is off screen.
<a class="badge" href="/work" data-dio="orbit" data-dio-by="auto" data-dio-radius="0.9" data-dio-tilt="20">Scroll to explore ✦</a>Notes
The form is real 3D seen through the page camera: a drum near the top of the screen shows more of its underside than one near the bottom, and the ring comes toward the viewer as it passes in front. Each letter is a small mesh bent around the form and lit by its normal, with a beveled edge that catches a highlight as it turns toward the light. fade dims the far side with depth.
The text stays real in the DOM, once: screen readers read it, search engines index it and find in page works. The copies that fill the circle are drawn only. While the form is drawn, a CSS filter hides the element without removing it, so a background or border on the element itself is hidden too; put them on a wrapper. Images inside the element are drawn with the form, in their place, and the ring passes behind and in front of them. A transparent cutout such as a product shot reads best.
With by="scroll" or by="drag" nothing is drawn while the form stands still. With by="auto" it turns at up to fps frames a second while on screen. Under reduced motion the form holds still with the front of the text toward the viewer; a drag still turns it, without the coast.
The canvas cannot draw background-clip: text, text-shadow, -webkit-text-stroke or vertical writing modes the way the browser does; such text stays as it is, with a warning in development. style and by rebuild the effect; the other params change live.