CardsPremium

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.

WebGLShader3DRaymarchingDrag

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

Card won at the last riddle — a castle's night-time clue trail — Interactive Ghost Card example 1

① Card won at the last riddle — a castle's night-time clue trail

WhenThe seventh riddle is solved: a window opens on card no. 07 “Banshee” on the left, with the bar of collected cards and two buttons. The card turns to show its back, then comes round to the skull again.
WhyThe player gets an object to handle, not an icon: they spin it, flip it, and show it at the gatehouse for their lantern.
Settingsdata-number="07", data-title="Banshee"; root without minimum height, card filling the window's height. “See the back” sends the Enter key to the card; for the capture, the scene also sends it every 1.7 s. Drag hint removed.
The ghost train is back — top of an autumn fair's website — Interactive Ghost Card example 2

② The ghost train is back — top of an autumn fair's website

WhenLanding on the fair's site, visitors see the title and prices on the left and, on the right, souvenir card no. 13 swaying and following the pointer.
WhyThe card is the gift handed out at every ride: showing it alive at the top says what you win and makes people want all thirteen.
Settingsdata-number="13", data-title="Spectre", 250 × 300 px card on a background matched to the shader's. No scene script: the sway and pointer tilt are the component's own. Drag hint shrunk to 9.5 px.
Looking for an opponent — waiting room of an online card game — Interactive Ghost Card example 3

③ Looking for an opponent — waiting room of an online card game

WhenThe player starts a ranked duel: in the middle of the panel, a small card spins next to the waiting timer until an opponent is found or the player cancels.
WhyThe wait shows an object from the game rather than a spinning circle, and the card can still be grabbed to pass the time.
Settingsdata-number="21", data-title="Poltergeist", 186 × 228 px card. The page sends the → key every 0.9 s (a spin impulse, with the component's momentum) and advances the timer; “Cancel” stops both.

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-scene has role="img" and an aria-label describing 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-hc class on .gst-scene lowers 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.

Chrome 88+✓ Full (measured in Chromium 149)
Firefox 89+✓ Full (measured in Firefox 151)
Safari 15+✓ Measured in WebKit 26.5; real Safari not checked
Edge 88+✓ Not checked (same engine as Chrome)
Mobile iOS 15+✓ Not checked on a device; a tap does nothing in touch WebKit (expected)
Android Chrome 88+✓ Measured in 390 px emulation: finger swipe, 4:3 card

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):

index.html — structure
<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 / propertyDefaultEffect
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

Because the depth is computed: each pixel of the front carries its ray on behind the glass to the skull. As the card turns, the skull shifts against the frame, like an object in a display case. A picture pasted on a CSS 3D card, such as Holographic Card 3D, stays flat against its face.
It is one of the most demanding effects in the catalogue: all the work happens on the graphics card, pixel by pixel. The two resolution caps and the off-screen pause keep the cost down, but avoid showing more than two at once, and lower PIX_MAX if the card covers a large area.
Each card is started only once: the second script sees that window.GhostCard already exists and only hands it the new cards. Both cards turn independently, with no WebGL error.