SFX Zero dependencies

A beam that finds your button.

It comes in from the top edge, passes through the primary button and lands on the surface below. It switches on a moment after the page has loaded.

The surface

The beam ends on this element's top edge. Use a screenshot, a mockup or a card.

Markup

Three things carry the wiring: data-beam on the section, a .beam layer inside it, and data-beam-target on the button the beam passes through. data-beam-surface is optional and says where it lands.

<section class="hero hero--center" data-beam data-beam-position="0.45">
  <div class="beam" aria-hidden="true"></div>
  <div class="container hero__content">
    …
    <a class="btn btn--primary" data-beam-target href="…">Request an invite</a>
    <figure data-beam-surface>…</figure>
  </div>
</section>

<script defer src="scripts/beam.f0ef30ca.js"></script>   <!-- only on pages that use it -->

Attributes

Behaviour lives in attributes on the host.

AttributeValuesDefault
data-beam-position0 (left) … 1 (right), or random0.5
data-beam-delaymilliseconds after the page has loaded2000

random is rolled once per page load and kept off the extreme edges so the beam stays in view. A value that isn't a number or random falls back to the centre.

Tokens

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

TokenDefaultWhat it does
--beam-colorvar(--color-brand)Any CSS colour
--beam-intensity0.50 off · 1 bright · 2 blazing. Keep it low behind text.
--beam-width0.20.2 a thin shaft … 1.6 a flood
--beam-smoke0.70 clean light … 1 thick fog
--beam-sparks0.60 none … 1.5 a lot
--beam-pace1Speed of the drift toward the source; 0 freezes it
--beam-fade1400msHow long it takes to switch on

Behaviour and limits

  • Opt-in. A site whose pages have no data-beam gets none of its CSS or JavaScript. The script is not part of the shared bundle.
  • Reduced motion. With prefers-reduced-motion the beam shows at once as a single still frame: no delay, no fade, no animation.
  • No WebGL2 or no JavaScript. A static cone of light is drawn by the CSS instead.
  • Pauses when it is off screen or the tab is hidden, and renders at 60% resolution, which is fine for soft light.
  • Dark themes. It adds light, so on a light background it will barely show.
  • One per page. Only the first [data-beam] is drawn.
  • Text. The beam sits behind the copy. If it crosses a paragraph, lower --beam-intensity and check the contrast.

Tuning

The panel at the bottom right moves the tokens live on this page. Copy tokens gives you the CSS for theme.css and the position attribute.