label
A flat label wrapped around a can, a bottle or a jar that turns to show all of it.
Live preview needs WebGPU or WebGL 2. A drinks can with a blue and cream Harbor Pale Ale label; it turns as the page scrolls and leans toward the pointer, the light running over the aluminium.
This example failed to draw.
Usage
Put it on img: the flat label, its whole width as printed; the container stands in the box of the image, as tall as fits. Without WebGL the plain label shows. start() registers label, 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 label<img class="can" src="/media/labels/label-can.webp" width="1240" height="560" data-dio="label" tabindex="0" style="touch-action: pan-y"/>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.can', 'label', { style: 'can', yaw: 0, pitch: 8, tilt: 6.9, turn: 180, spin: 0, gloss: 0.5, shadow: 0.5,})import { start } from '@dioramajs/diorama'import label from '@dioramajs/model/label'
const app = start()app.attach('.can', label({ style: 'can', yaw: 0, pitch: 8, tilt: 6.9, turn: 180, spin: 0, gloss: 0.5, shadow: 0.5,}))Page transitions
Leaves by dithering its pixels away while shrinking to 96%, and its shadow fades with it. 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 | 'can' | 'bottle' | 'jar' | 'can' | Kind of container. can: a 330 ml drinks can, the label printed all around its body, for beer, soda and coffee; bottle: a 750 ml bottle of colored glass with a foil cap, the label on its body, for wine, spirits and oils; jar: a squat glass jar with a twist lid, for cosmetics, honey, coffee and sauces. |
colorrebuildsdata-dio-color | string | '' | Color of the body: the metal of a can, the glass of a bottle, what fills a jar. Empty takes the default of the style: aluminium, green glass, amber. |
caprebuildsdata-dio-cap | string | '' | Color of the cap: the lid of a can, the foil of a bottle, the lid of a jar. Empty takes the default of the style. |
yawdata-dio-yaw | number-180 to 180° | 0 | Rest turn; 0 shows the middle of the label. |
pitchdata-dio-pitch | number-35 to 35° | 8 | Rest tilt; positive shows the top, as seen from a little above. |
tiltdata-dio-tilt | number0 to 25° | 6.9 | How far it leans toward the pointer: 0 turns the lean off. |
turndata-dio-turn | number-720 to 720° | 180 | Turns while the page scrolls past: 360 is a whole turn from entering the viewport to leaving it, 180 shows the label from one end to the other. 0 turns it off. |
spindata-dio-spin | number-180 to 180 deg/s | 0 | Idle turn while nobody touches it, pausing under the pointer and for 1.5 s after: 0 turns it off. |
glossdata-dio-gloss | number0 to 1 | 0.5 | Shine of the light on the print: 0 is matte paper. |
dragdata-dio-drag | boolean | true | Turns it under a drag and tips it a little, and with the arrow keys when it has a tabindex. |
shadowdata-dio-shadow | number0 to 1 | 0.5 | Density of the shadow on the page. |
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, presence, progress, reducedMotion and width
. Draws only while something on it moves, then stops. While the page scrolls with turn, and while it leans, coasts after a drag, eases a key step, or spin turns it; none at rest, and pointer moves elsewhere draw nothing. 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. It rests as posed: no lean, spin or scroll turn. Dragging and arrow keys still turn it, without coasting.
Runs on every device. Nothing leans; the scroll turns it. A finger turns it only when the element has `touch-action: pan-y` or `none`, and tips it only with `none`; otherwise the gesture scrolls the page.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { label: { reducedMotion: 'off' } } })Cost and quality
- Download
- 4.4 KB min+gzip the first time a page uses it
- GPU
- One body of about two thousand triangles with a simple light, no environment map.
- Memory
- The label image.
- Frames
- Idle at rest
It runs from the low tier up. Every tier draws it the same way. The quality plugin picks the tier for each device.
Recipes
A wine bottle turned by a drag
style="bottle" puts the label on a 750 ml bottle of colored glass with a foil cap. A wine label is narrow, so it covers part of the body, as on a real bottle. turn="0" stops the scroll turn and leaves the bottle to a drag and the arrow keys.
Live preview needs WebGPU or WebGL 2. A dark green wine bottle with a cream Hillside Riesling 2024 label, turned a little to the left; a drag turns it all the way round.
This example failed to draw.
<img class="bottle" src="/media/labels/label-wine.webp" width="800" height="960" data-dio="label" data-dio-style="bottle" data-dio-turn="0" data-dio-yaw="-20" tabindex="0" style="touch-action: pan-y"/>A jar with a colored lid
style="jar" is a squat glass jar with a twist lid. color is what fills the jar, seen through the glass, and cap is the lid. A higher pitch shows the top of the lid.
Live preview needs WebGPU or WebGL 2. A glass jar of amber honey with a gold lid and a dark label with honeycomb and Wildflower Honey on it.
This example failed to draw.
<img class="jar" src="/media/labels/label-jar.webp" width="1500" height="500" data-dio="label" data-dio-style="jar" data-dio-color="#c98a1b" data-dio-cap="#b8902f" data-dio-pitch="16"/>Notes
Use the flat label as it goes to print, its whole width. The label keeps its proportions: its height takes the label band of the container and its width decides how far around it reaches. A label longer than the body goes once round and gets a lower band. A label with transparent edges, such as a die-cut shape, shows the glass or the metal around it.
Size the image’s box for the container and keep the label undistorted with object-fit: contain: the container stands in the box as tall as fits. Without WebGL the flat label shows in the same box, all of it readable.
The container draws only while it moves: the scroll with turn, a drag, the lean or the idle spin. On touch screens the scroll turns it; a finger turns it only when the image has touch-action: pan-y or none.
style, color and cap rebuild the effect; every other param changes live.