Liking cljdoc? Tell your friends :D

x-kinetic-canvas

Animated canvas background component with slotted content. Renders particle/character animations behind any content placed inside the element.

Tag

<x-kinetic-canvas type="starfield">
  <h1>Content renders on top</h1>
</x-kinetic-canvas>

Observed Attributes

AttributeTypeDefaultDescription
typestringstarfieldAnimation type: starfield, bubbles, matrix
variantstringmotionType-specific variant. Starfield: motion, twinkle
speedstringmediumAnimation speed: slow, medium, fast, or numeric multiplier
densitystringmediumEntity density: low, medium, high, or numeric multiplier
fullscreenbooleanfalseWhen present, positions fixed to fill the viewport
pausedbooleanfalseWhen present, pauses the animation loop

Properties

PropertyTypeReflects Attribute
typestringtype
variantstringvariant
speedstringspeed
densitystringdensity
fullscreenbooleanfullscreen
pausedbooleanpaused

Events

None.

Methods

None.

Slots

SlotDescription
defaultContent rendered on top of the animated background

CSS Custom Properties

PropertyDefault (light)Default (dark)Description
--x-kinetic-canvas-bgvar(--x-color-bg, #f0f0f5)var(--x-color-bg, #0a0a1a)Canvas background fill
--x-kinetic-canvas-color-1var(--x-color-text, #1a1a2e)var(--x-color-text, #ffffff)Primary entity colour
--x-kinetic-canvas-color-2var(--x-color-primary, #2563eb)var(--x-color-primary, #60a5fa)Secondary entity colour
--x-kinetic-canvas-color-3var(--x-color-secondary, #7c3aed)var(--x-color-secondary, #c084fc)Tertiary entity colour
--x-kinetic-canvas-matrix-font-size1414Font size (px) for matrix rain characters
--x-kinetic-canvas-z-1-1z-index for fullscreen mode (behind content by default)

Colours integrate with x-theme tokens and adapt to light/dark colour scheme automatically.

Animation Types

starfield

Stars at varying depths with two variants:

  • motion — stars drift outward from center with parallax depth
  • twinkle — static star positions with pulsing brightness

bubbles

Soft circles floating upward with horizontal drift. Wrap around at screen edges.

matrix

Falling columns of characters (Katakana + Latin) with brightness falloff from head to tail.

Accessibility

  • Canvas element has aria-hidden="true"
  • Respects prefers-reduced-motion: reduce — renders a single static frame, no animation loop
  • Animation pauses when the element is scrolled offscreen (IntersectionObserver)

Performance

  • Uses requestAnimationFrame for smooth 60fps animation
  • Pauses automatically when offscreen via IntersectionObserver
  • Canvas sized with devicePixelRatio for sharp rendering on HiDPI displays
  • Entities stored as mutable JS arrays for minimal GC pressure

Usage Examples

<!-- Page background -->
<x-kinetic-canvas type="starfield" fullscreen></x-kinetic-canvas>

<!-- Section background -->
<x-kinetic-canvas type="bubbles" speed="slow" density="low" style="height: 400px;">
  <div style="padding: 2rem; color: white;">
    <h2>Hero section</h2>
    <p>Content on top of animated bubbles</p>
  </div>
</x-kinetic-canvas>

<!-- Custom colours -->
<x-kinetic-canvas type="matrix"
  style="--x-kinetic-canvas-bg: #000;
         --x-kinetic-canvas-color-1: #0f0;
         --x-kinetic-canvas-color-2: #0a0;
         --x-kinetic-canvas-color-3: #050;">
</x-kinetic-canvas>

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close