A light that shows your mark.
A cone of light rises from below and ends in a bright disc on the cloud, with your logo cut out of it. It switches on a moment after the page has loaded.
Markup
Three things carry the wiring: data-searchlight on the section, an empty
.searchlight layer inside it, and data-searchlight-src, the image the light is cut by.
The layer is decorative: it is hidden from assistive tech.
<section class="hero hero--center" data-searchlight data-searchlight-src="logo.svg"
data-searchlight-at="0.14,0.3" data-searchlight-source="0.1,1.08" data-searchlight-size="0.1"
data-searchlight-at-narrow="0.5,0.15" data-searchlight-source-narrow="0.5,0.4" data-searchlight-size-narrow="0.24">
<div class="searchlight" aria-hidden="true"></div>
<div class="container hero__content"> … </div>
</section>
<script defer src="scripts/searchlight.c7d05a14.js"></script> <!-- only on pages that use it -->
Attributes
All on the section. Positions are fractions of the section: x from the left,
y from the top.
| Attribute | Values | Default |
|---|---|---|
data-searchlight-src | the silhouette: an image whose transparency is the shape (an opaque image is used by darkness). Without it, or if it fails to load, the disc is plain. | none |
data-searchlight-at | the disc centre, x,y | 0.8,0.26 |
data-searchlight-source | the lamp, x,y (y above 1 is below the section) | 0.12,1.06 |
data-searchlight-size | the disc radius as a fraction of the section's width | 0.13 |
data-searchlight-at-narrow, -source-narrow, -size-narrow | the same three, used below 640px. Any left out falls back to its wide value. | the wide values |
data-searchlight-delay | milliseconds after the page has loaded | 2000 |
Tokens
The look is a token, set in the client's theme.css. Numbers are unitless.
| Token | Default | What it does |
|---|---|---|
--searchlight-color | var(--color-brand) | The colour of the light |
--searchlight-intensity | 0.8 | 0 = off, 1 = bright, 2 = blazing |
--searchlight-fog | 0.8 | The haze around the cone |
--searchlight-haze | 0.6 | The cloud the disc lands on |
--searchlight-flicker | 0.5 | The switch-on stutter and slow shimmer. 0 = steady. |
--searchlight-pace | 1 | How fast the cloud drifts. 0 = frozen. |
--searchlight-logo-scale | 0.62 | The silhouette's size inside the disc |
--searchlight-logo-dark | 0.9 | How dark the silhouette is cut |
--searchlight-focus | 0.35 | Edge softness of the disc and silhouette |
--searchlight-fade | 1400ms | How long the static glow takes to appear |
Placement
Light adds light, so it can wash out any text it crosses. The effect does not move out of the way of your copy: you place it where there is none.
- Put the disc and the cone in empty space. On a centred hero the margin beside the copy is clear: this page puts the disc at the left with the lamp just below it, so the cone runs up the margin and never touches a word.
- Check it on a phone. The copy fills the width, so there is no clear margin. Make room instead: add padding above the copy (this page does) and use
-at-narrow,-source-narrowand-size-narrowto put the disc in that space with a short cone. - Lower the intensity if it has to cross a heading:
--searchlight-intensity: 0.4keeps the shape and leaves the words readable. - Check the subtitle. It is the text most often crossed, because it sits where the cone passes.
Behaviour and limits
- Opt-in. A site whose pages have no
data-searchlightgets none of its CSS or JavaScript. The script is not part of the shared bundle. - Reduced motion. One lit still frame, on at once: no delay, no fade, no shimmer.
- Without WebGL2 or JavaScript. A static cone and disc (no silhouette) appear instead, in the same place and colour. With JavaScript they fade in at the switch-on; without it they are simply there.
- It pauses when it is off screen or the tab is hidden, and renders at 60% resolution.
- Dark themes. It adds light, so on a light background it will barely show.
- One per page. Only the first
[data-searchlight]is drawn. - Decorative. The layer is
aria-hidden; anything the silhouette says must also be said in text.
Tuning
The panel at the bottom right changes the tokens and the placement on the example above.
Power on replays the switch-on. Copy gives you the attributes and the CSS for
theme.css. It edits the wide placement; below 640px the -narrow values apply.