# 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.

The letters bend around a real 3D shape seen through the page camera. On the drum the front letters face you, bright and beveled, while the ones on the far side show mirrored through the gaps, smaller and dimmed by depth. Lit by their normals, letters darken as they turn away and a highlight runs over their bevels as they pass the light. The globe wraps rows of the text from pole to pole, and the ring orbits the middle of the element, passing behind its image and in front of it again.

Module `text`, category Text. Import `@dioramajs/text/orbit`. [Source](https://github.com/MasterKurosava/diorama/blob/main/packages/text/src/orbit.ts)

A night market poster whose words circle a painted paper lantern on a tilted ring, passing behind it and in front of it again.

```html title="index.html"
<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" alt="A paper lantern painted with a sunrise over hills">
    <figcaption>Night market · Lantern festival ·</figcaption>
  </figure>
</section>
```

## 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.

```html
<h2 data-dio="orbit" data-dio-radius="0.6">Made to be noticed ✦</h2>
```

- `img` inside: Images inside are drawn in their place with the form, which passes behind and in front of them.

In page transitions: The form fades with the page.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'cylinder' \| 'sphere' \| 'ring'` | `'cylinder'` | cylinder wraps lines around a drum; sphere covers a globe; ring orbits the box center. |
| `by` (rebuilds) | `data-dio-by` | `'scroll' \| 'drag' \| 'auto'` | `'scroll'` | scroll turns it with the page; drag lets the visitor spin it; auto turns it by itself. |
| `radius` | `data-dio-radius` | `number` 0.1 to 2 | `1` | Radius of the form as a share of half the box width (half its shorter side for sphere). |
| `tilt` | `data-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. |
| `roll` | `data-dio-roll` | `number` -45 to 45° | `0` | Sideways lean of the form; positive lifts its right side. |
| `speed` | `data-dio-speed` | `number` -90 to 90° | `20` | Turn rate: degrees a second with auto, degrees per 100 px of scroll; 0 holds it. |
| `repeat` | `data-dio-repeat` | `boolean` | `true` | Copies the text to fill the circle all the way around; off shows it once. |
| `fade` | `data-dio-fade` | `number` 0 to 1 | `0.55` | How much the far side of the form fades with depth; 0 keeps it as solid as the front. |
| `pause` | `data-dio-pause` | `boolean` | `true` | With auto, eases the turn to a stop under the pointer or keyboard focus. |
| `fps` | `data-dio-fps` | `number` 10 to 60 | `60` | Most frames a second while it turns by itself. At most low 30. |
| `color` | `data-dio-color` | `color` | `'currentColor'` | Color of the letters; currentColor or empty keeps the text color. |

Changing a param marked rebuilds re-runs the effect setup.

### Variants

- `style`: `cylinder`, `sphere`, `ring`
  - `cylinder` wraps lines around a drum.
  - `sphere` covers a globe.
  - `ring` orbits the box center.
- `by`: `scroll`, `drag`, `auto`
  - `scroll` turns it with the page.
  - `drag` lets the visitor spin it.
  - `auto` turns it by itself.

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`height`](/docs/api/inputs#input-height), [`opacity`](/docs/api/inputs#opacity), [`reducedMotion`](/docs/api/inputs#input-reducedMotion), [`visible`](/docs/api/inputs#input-visible), [`width`](/docs/api/inputs#input-width), [`x`](/docs/api/inputs#input-x), [`y`](/docs/api/inputs#input-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. See [how a frame is decided](/docs/concepts/frames).

## 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.

```ts
import { start } from '@dioramajs/diorama'

start({ effects: { orbit: { reducedMotion: 'off' } } })
```

## Cost and quality

Loads 11.4 KB 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.

- 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.

See [the quality plugin](/docs/effects/quality).

## 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.

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.

```html title="index.html"
<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.

A shop's shipping note beside a blue globe made of the words Shipping to 48 countries, which you can spin with the pointer.

```html title="index.html"
<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.

```html
<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.

## Related

- [assemble](/docs/effects/assemble.md): Thousands of lit particles fly out of the depth around the page and gather into a heading.
- [blinds](/docs/effects/blinds.md): A heading printed across real 3D slats that turn over in a wave, lit and casting shadows, to show it.
- [counter](/docs/effects/counter.md): Stats count up to their value on real 3D mechanics: odometer drums, slot machine reels or flip cards.
- [dust](/docs/effects/dust.md): A heading crumbles into fine sand that lifts off the page and drifts away in depth as it scrolls out, or on a click.
- [emboss](/docs/effects/emboss.md): Letters pressed into or raised out of paper, leather, brushed metal, stone or plaster, lit by a light that follows the pointer.
- [extrude](/docs/effects/extrude.md): A headline becomes a solid 3D block: beveled letters with lit side walls, seen in perspective, that turn toward the pointer.
- [fire](/docs/effects/fire.md): The letters burn: flames rise from their tops, sparks drift up in depth and the firelight flickers on the page.
- [hologram](/docs/effects/hologram.md): A heading becomes a 3D hologram: projected from a glowing emitter, built of slices in depth, crossed by scan lines.
- [Reduced motion](/docs/guides/reduced-motion.md)
- [Performance and quality](/docs/guides/performance.md)
