Interactive Ghost Card
A neon card computed frame by frame in WebGL: a ghost skull floats behind the glass of the front, and you spin it a full 360° with a finger or the mouse, with momentum.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Cards has 43 effects, including 6 free. Explore the category →
3 usage examples



How it works
None of it is a picture: one <canvas> per card and a shader that casts one ray per pixel (raymarching). The ray meets the card (a rounded slab 0.048 thick), then, through the front glass, a skull described by distance functions and set 0.7 units deeper. The cyan eyes pulse, wisps rise around the skull, and the back carries a round emblem. The number (data-number) and small title (data-title) are painted on a 2D canvas and applied to the front as a texture.
At rest, the card sways on its own (±0.6 radian of yaw). The mouse tilts it towards the pointer. Dragging turns it (0.012 radian per pixel); on release it keeps the momentum of the gesture, slows down and lands on the nearest face before the swaying resumes. If the pointer stopped more than 80 ms before release, nothing is thrown. Keyboard: ← → give a spin impulse, ↑ ↓ tilt, Enter or Space flip it.
The cost is per pixel, hence two caps: device pixel ratio limited to 1.5 and 900,000 pixels at most. The loop stops when the card leaves the screen or the tab is hidden, and time is measured between frames rather than counted per frame. Several cards on one page each get their own WebGL context. Without WebGL, or after a lost context, a still card drawn in CSS and SVG takes over.
Accessibility
- Accessible name:
.gst-scenehasrole="img"and anaria-labeldescribing the card and its controls; the canvas is hidden from screen readers. Rewrite that text for each card (number, name), and drop the drag instructions if your audience often gets the fallback card. - Keyboard: the card takes focus (
tabindex="0") and shows a 2 px magenta outline. Arrows and Enter/Space only act on the focused card and do not scroll the page. - Touch: a horizontal swipe turns the card, a vertical one scrolls the page (
touch-action: pan-y). A plain tap flips nothing, and the pointer-following tilt is for the mouse only. - Reduced motion: the card is shown still, at three-quarter view; no sway, no momentum, no hover tilt, and the wisps freeze. Arrows turn it in 15° steps, Enter flips it at once, and the “Drag to spin” hint stays on screen.
- Contrast: the
gst-hcclass on.gst-scenelowers the glow, reflections and smoke in the shader for a crisper image.
Browser compatibility
WebGL 1, pointer events and aspect-ratio. Measured on the sold code pasted into a blank page: Chromium 149 (122 frames/s with the graphics card), Firefox 151 (105 frames/s), WebKit 26.5 (32 frames/s, software rendering of the test tool). In all three: two cards on one page spin independently, full keyboard control, still image under reduced motion, fallback card shown when WebGL is switched off.
Without WebGL (browser, company policy, blocklisted graphics card) or after a lost context, the gst-nogl class shows a still neon card in CSS and SVG, with the number but no title; it does not turn and the drag hint is hidden.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0842-root">
<div class="gst-scene" tabindex="0" role="img" data-number="13" data-title="Spectre" aria-label="…">
<canvas class="gst-canvas" aria-hidden="true"></canvas>
<div class="gst-fallback" aria-hidden="true">
<div class="gst-fb-card"><svg>…</svg><span class="gst-fb-num">13</span></div>
</div>
<div class="gst-hint" aria-hidden="true">…</div>
</div>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
Number and title (HTML — data-number, data-title on .gst-scene) |
13 and “Spectre” | Painted on the front texture at start-up. Beyond two characters the number drops from 44 to 32 px; the title is set in spaced capitals. |
Neon strength (JS — GhostCard.setNeon(v)) |
1 | 0.5 for a duller edge and emblem, 1.5 for more glare. Applies to every card on the page. |
Sway speed (JS — GhostCard.setAutoSpeed(v)) |
1 | 0 freezes the sway where it is; 2 makes it twice as fast. |
Flip from a script (JS — GhostCard.flip()) |
— | Flips every card. For a single one, send it the Enter key: el.dispatchEvent(new KeyboardEvent('keydown', {key: 'Enter'})). |
Card added after load (JS — GhostCard.init()) |
— | Starts new .gst-scene elements without touching the ones already running. |
Format and caps (CSS aspect-ratio of .gst-scene; JS DPR_MAX, PIX_MAX) |
16 / 10 (4 / 3 on a portrait phone), 1.5 and 900,000 | For a lone card, give .gst-scene a fixed height. Lower PIX_MAX to 400,000 on a page showing several. |
Card + panel (CSS — gst-usage class on .gst-scene) |
Not used | The CSS includes a two-column layout: the card on the left, a .gst-panel on the right (.gst-rarity, h4, p, .gst-btn, .gst-meta). |
FAQ
PIX_MAX if the card covers a large area.window.GhostCard already exists and only hands it the new cards. Both cards turn independently, with no WebGL error.