№ 005

Fling Stack

A swipeable card stack — fling left or right, and flung cards loop to the back.

Version
1.0.0
Download
7 KB · 3 files
Added
Oct 26, 2026
Built with
HTML, CSS, JS
Needs
Google Fonts
Tags
swipe, cards, gesture

Usage

Copy fling-stack.css and fling-stack.js (and assets/, if there is one) into your project, then:

  const stack = new FlingStack(element, {
    cards: [{ tag, title, subtitle, color, color2 }],
    onChange(card, index) {},          // the card now on top
    onSwipe(card, 'left' | 'right') {} // a card was flung away
  });
  stack.swipe('left' | 'right');       // fling the top card programmatically
Cards loop: a flung card goes to the back of the stack.

Source

/* Fling — a swipeable card stack. Drag the top card away; the next one springs forward. */

.fs {
  position: relative;
  width: min(320px, 100%);
  aspect-ratio: 320 / 440;
  outline: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.fs:focus-visible { outline: 2px solid var(--fs-focus, #17141f); outline-offset: 14px; border-radius: 36px; }

.fs-card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 22px;
  overflow: hidden;
  border-radius: 28px;
  color: #fff;
  text-align: left;
  background: linear-gradient(155deg, var(--c1), var(--c2));
  box-shadow:
    0 26px 40px -18px rgba(30, 22, 48, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
  transform-origin: 50% 115%;
  touch-action: none;
  cursor: grab;
  will-change: transform;
  transition: transform 0.55s cubic-bezier(0.3, 1.35, 0.5, 1), opacity 0.3s, filter 0.3s;
}

.fs-card.is-dragging { transition: filter 0.3s; cursor: grabbing; }
.fs-card.is-gone { transition: transform 0.45s cubic-bezier(0.2, 0.7, 0.3, 1), opacity 0.45s ease-in; pointer-events: none; }
.fs-card.is-reset { transition: none; }

/* soft light blob in the corner */
.fs-card::before {
  content: "";
  position: absolute;
  top: -70px;
  right: -70px;
  width: 240px;
  height: 240px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0) 65%);
  pointer-events: none;
}

.fs-top, .fs-bottom { position: relative; }

.fs-tag {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(6px);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.fs-title {
  margin: 0;
  font-size: 44px;
  font-weight: 800;
  letter-spacing: -0.045em;
  line-height: 1;
}

.fs-sub { margin: 10px 0 0; font-size: 16px; line-height: 1.35; opacity: 0.88; }

.fs-count { margin-top: 18px; font-size: 12px; font-weight: 500; letter-spacing: 0.12em; opacity: 0.7; }

.fs-stamp {
  position: absolute;
  top: 64px;
  padding: 4px 12px;
  border: 3px solid;
  border-radius: 10px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.08em;
  opacity: 0;
  pointer-events: none;
}

.fs-stamp.keep { left: 22px; transform: rotate(-14deg); color: #d4ff8a; }
.fs-stamp.skip { right: 22px; transform: rotate(14deg); color: #ffd3dc; }

.fs-live {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

@media (prefers-reduced-motion: reduce) {
  .fs-card { transition: opacity 0.2s, filter 0.2s; }
  .fs-card.is-gone { transition: opacity 0.2s; }
}