Skip to content

Class: SSOverlay ​

Defined in: ssplayer-webgl/src/SSOverlay.ts:58

One WebGL context for a whole page of animations, positioned by DOM elements.

An overlay is a full-viewport, transparent, pointer-events-none <canvas> fixed behind the page's own content. Elements register with it and get an SSPlayer; every frame the overlay reads each element's rect and writes it into that player's box, so the animation is drawn where the element is without the element owning a canvas at all.

This is what makes an arbitrary number of animations viable on one page: browsers cap live WebGL contexts at roughly 8-16, and this costs one regardless of how many elements register. The same page built from one canvas per animation starts blanking canvases at around a dozen.

What it gives up, and why:

  • One z-index. Everything drawn here shares the overlay canvas's place in the stacking order, so page content cannot be interleaved between two overlay animations. An element that must sit in normal flow wants its own surface instead.
  • Rectangular clipping only. Clipping is a scissor rect, so border-radius, clip-path, filter and CSS transforms on the host element do not shape the animation — it is not drawn inside that element's box, only at its position.
  • Blend modes composite against the overlay, which is transparent, so framebuffer-reading blends (Add / Screen / Mul) have nothing behind them unless the player opts into its own backdrop.

Positions are read once per frame, all before anything is written, so the per-frame layout reads stay cheap. Off-screen players are skipped entirely.

Properties ​

canvas ​

readonly canvas: HTMLCanvasElement

Defined in: ssplayer-webgl/src/SSOverlay.ts:75


id ​

readonly id: string

Defined in: ssplayer-webgl/src/SSOverlay.ts:90


surface ​

readonly surface: SSSurface

Defined in: ssplayer-webgl/src/SSOverlay.ts:74

Accessors ​

size ​

Get Signature ​

get size(): number

Defined in: ssplayer-webgl/src/SSOverlay.ts:164

How many players this overlay is drawing — all on one context.

Returns ​

number

Methods ​

attach() ​

attach(el, player): void

Defined in: ssplayer-webgl/src/SSOverlay.ts:139

Track el's rect as player's box.

Parameters ​

el ​

HTMLElement

player ​

SSPlayer

Returns ​

void


createPlayer() ​

createPlayer(el, options?): SSPlayer

Defined in: ssplayer-webgl/src/SSOverlay.ts:132

Create a player positioned by el, and start tracking it.

Parameters ​

el ​

HTMLElement

options? ​

SSPlayerOptions

Returns ​

SSPlayer


destroy() ​

destroy(): void

Defined in: ssplayer-webgl/src/SSOverlay.ts:257

Tear the overlay down and remove its canvas.

Returns ​

void


detach() ​

detach(player): void

Defined in: ssplayer-webgl/src/SSOverlay.ts:150

Stop tracking player. Does not destroy it.

Parameters ​

player ​

SSPlayer

Returns ​

void


onResized() ​

onResized(listener): () => void

Defined in: ssplayer-webgl/src/SSOverlay.ts:179

Called after the overlay has resized its canvas, so hosts that placed players in drawing-buffer pixels can recompute those coordinates.

A player's transform is stored in buffer pixels, and a resize changes how many of those there are per CSS pixel — so a host that converted once, when the player was created, is left holding coordinates for a canvas that no longer exists, and its characters drift on the next window resize. There is nothing the overlay can fix on their behalf: only the host knows what the numbers meant. Returns an unsubscribe function.

Parameters ​

listener ​

() => void

Returns ​

() => void


getOrCreate() ​

static getOrCreate(id?, options?): SSOverlay

Defined in: ssplayer-webgl/src/SSOverlay.ts:65

The overlay for id, created on first use. Sharing one id is the whole point — every extra overlay is another WebGL context.

Parameters ​

id? ​

string = 'default'

options? ​

SSOverlayOptions = {}

Returns ​

SSOverlay