SFX Zero dependencies

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.

AttributeValuesDefault
data-searchlight-srcthe 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-atthe disc centre, x,y0.8,0.26
data-searchlight-sourcethe lamp, x,y (y above 1 is below the section)0.12,1.06
data-searchlight-sizethe disc radius as a fraction of the section's width0.13
data-searchlight-at-narrow, -source-narrow, -size-narrowthe same three, used below 640px. Any left out falls back to its wide value.the wide values
data-searchlight-delaymilliseconds after the page has loaded2000

Tokens

The look is a token, set in the client's theme.css. Numbers are unitless.

TokenDefaultWhat it does
--searchlight-colorvar(--color-brand)The colour of the light
--searchlight-intensity0.80 = off, 1 = bright, 2 = blazing
--searchlight-fog0.8The haze around the cone
--searchlight-haze0.6The cloud the disc lands on
--searchlight-flicker0.5The switch-on stutter and slow shimmer. 0 = steady.
--searchlight-pace1How fast the cloud drifts. 0 = frozen.
--searchlight-logo-scale0.62The silhouette's size inside the disc
--searchlight-logo-dark0.9How dark the silhouette is cut
--searchlight-focus0.35Edge softness of the disc and silhouette
--searchlight-fade1400msHow 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-narrow and -size-narrow to put the disc in that space with a short cone.
  • Lower the intensity if it has to cross a heading: --searchlight-intensity: 0.4 keeps 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-searchlight gets 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.