reveal
The image wipes in with a soft noisy edge as it scrolls into view, or fades, opens in bands or from the center.
Live preview needs WebGPU or WebGL 2. A photo of misty ridges that wipes in with a soft, uneven edge.
This example failed to draw.
Every switch and slider plays the reveal again.
Usage
Put it on img, video. start() registers reveal, 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 reveal<img class="ridges" src="/media/ridges.jpg" width="1800" height="1200" data-dio="reveal"/>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.ridges', 'reveal', { style: 'wipe', trigger: 'view', direction: 'up', duration: 1.2, delay: 0, threshold: 0.2, zoom: 1.12, softness: 0.12,})import { start } from '@dioramajs/diorama'import reveal from '@dioramajs/media/reveal'
const app = start()app.attach('.ridges', reveal({ style: 'wipe', trigger: 'view', direction: 'up', duration: 1.2, delay: 0, threshold: 0.2, zoom: 1.12, softness: 0.12,}))Page transitions
Leaving a page closes the wipe again, entering opens it. A flight target lands on the revealed image. 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 | 'wipe' | 'fade' | 'blinds' | 'iris' | 'wipe' |
|
triggerrebuildsdata-dio-trigger | 'view' | 'scroll' | 'view' |
|
directionrebuildsdata-dio-direction | 'up' | 'down' | 'left' | 'right' | 'up' | Where the wipe travels: up uncovers from the bottom. The fade drifts the same way; the iris ignores it. |
durationdata-dio-duration | number0.2 to 3 s | 1.2 | Length of the reveal. |
delaydata-dio-delay | number0 to 2 s | 0 | Wait after the trigger, for a cascade across a grid. |
thresholddata-dio-threshold | number0 to 1 | 0.2 | Share of the image height that must be in view, above the bottom tenth of the viewport, before it plays. |
zoomdata-dio-zoom | number0 to 1.5 | 1.12 | Scale the picture settles from; 1 or 0 for none. |
softnessdata-dio-softness | number0 to 0.5 | 0.12 | Width of the soft edge as a share of the image; uneven in wipe and iris, plain in blinds. |
seedrebuildsdata-dio-seed | number1 to 100 | 1 | Shape of the uneven edge. |
Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.
Inputs and frames
It reads presence and size
. Draws only while something on it moves, then stops. Only while revealing, and with trigger scroll while scrolling; none at rest. How a frame is decided.
Reduced motion and touch
With reduced motion it is off and the element shows as plain HTML. Off: the image is shown as it is, and the engine does not load for it.
Runs on every device. The same as with a mouse: it follows the scroll.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { reveal: { reducedMotion: 'static' } } })Cost and quality
- Download
- 1.4 KB min+gzip the first time a page uses it
- GPU
- One texture read of the image and one of a small noise tile per pixel.
- Memory
- The shared texture of the image and a shared 64 x 64 noise tile.
- 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
Cascade across a grid
Give each image a slightly longer delay than the one before it. The row enters together, so the prints open one after another from left to right.
Live preview needs WebGPU or WebGL 2. Three prints that wipe in one after another.
This example failed to draw.
Each print waits 0.15 s longer than the one before it.
<div class="prints"> <img src="/media/prints/dawn.jpg" width="1000" height="1000" data-dio="reveal" /> <img src="/media/prints/dusk.jpg" width="1000" height="1250" data-dio="reveal" data-dio-delay="0.15" /> <img src="/media/prints/lanterns.jpg" width="1000" height="1250" data-dio="reveal" data-dio-delay="0.3" /></div>Scrub it with the scroll
With data-dio-trigger="scroll" the reveal follows the scroll position both ways: the image opens as it rises to the middle of the viewport and closes again when you scroll back. Use it for a wide image that a reader passes slowly, such as a panorama between two sections.
<img src="/media/ridges.jpg" data-dio="reveal" data-dio-trigger="scroll" data-dio-direction="right"/>A quiet fade for long reads
The fade style drops the edge and drifts the image 40 px into place. Set zoom to 1 as well and an article’s figures arrive without drawing attention away from the text.
<img src="/media/prints/night.jpg" data-dio="reveal" data-dio-style="fade" data-dio-zoom="1" data-dio-duration="0.8"/>Bands across a wide banner
The blinds style opens the image in bands, each half a reveal after the one before it. A low softness keeps the bands crisp, which suits a banner of flat shapes or type.
<img src="/media/ridges.jpg" data-dio="reveal" data-dio-style="blinds" data-dio-direction="down" data-dio-softness="0.02"/>Notes
An image that is already in view when the page opens stays as it is: the reveal plays only for images the reader scrolls to, so nothing on the first screen disappears to play an intro. The example on this page plays again after each change for the same reason.
The reveal starts when threshold of the image height is in view above the bottom tenth of the viewport. An image that only peeks in at the bottom edge has not been looked at yet, so it waits.
style, trigger, direction and seed rebuild the effect when they change. Set them in the markup rather than switching them while the image is on screen.