{
  "format": "putcode/playground@1",
  "id": "ef9ab375-a70b-5da5-978e-b22a30e1610a",
  "url": "https://putcode.dev/u/mighil/s/z2dhccocij",
  "title": "Price cut",
  "description": "Old price crosses out while the new one counts to $29.",
  "category": "animations",
  "tags": [
    "commerce",
    "micro-interaction"
  ],
  "visibility": "public",
  "status": "published",
  "revision": 1,
  "author": "mighil",
  "forked_from": null,
  "created_at": "2026-12-02T12:04:29.000Z",
  "updated_at": "2026-12-02T14:20:44.069Z",
  "published_at": "2026-12-02T12:04:29.000Z",
  "source": {
    "html": "<div class=\"price-cut\" id=\"price-cut\">\n        <span class=\"was\"><i class=\"strike\" aria-hidden=\"true\"></i>$48</span>\n        <span class=\"now\">$<b class=\"num\">48</b></span>\n      </div>\n",
    "css": "/* Auto light / dark — follows prefers-color-scheme */\n:root{\n  color-scheme: light dark;\n  --text-color: hsl(0, 0%, 18%);\n  --heading-color: hsl(0, 0%, 18%);\n  --background-color: hsl(0, 0%, 99%);\n  --bg-color: hsl(0, 0%, 99%);\n  --link-color: hsl(0, 0%, 18%);\n  --visited-color: hsl(0, 0%, 18%);\n  --blockquote-color: hsl(0, 0%, 18%);\n  --code-bg-color: hsl(0, 0%, 95%);\n  --code-color: hsl(0, 0%, 18%);\n  --sub-color: hsl(0, 0%, 29%);\n}\n@media (prefers-color-scheme: dark){\n:root{\n  --text-color: hsla(0, 0%, 93%, 1);\n  --heading-color: hsla(0, 0%, 93%, 1);\n  --background-color: hsla(0, 0%, 0%, 1);\n  --bg-color: hsla(0, 0%, 0%, 1);\n  --link-color: hsla(0, 0%, 93%, 1);\n  --visited-color: hsla(0, 0%, 93%, 0.85);\n  --blockquote-color: hsla(0, 0%, 93%, 1);\n  --code-bg-color: hsla(0, 0%, 8%, 1);\n  --code-color: limegreen;\n  --sub-color: hsla(0, 0%, 93%, 0.78);\n}\n}\n\n/* Preview layout */\nbody {\n  margin: 0;\n  min-height: 100vh;\n  display: grid;\n  place-items: center;\n  padding: 24px;\n  box-sizing: border-box;\n  background: var(--background-color);\n  color: var(--text-color);\n  font: 15px/1.5 system-ui, -apple-system, \"Segoe UI\", sans-serif;\n}\n\n.price-cut{display:inline-flex;align-items:baseline;gap:10px;font-variant-numeric:tabular-nums}\n\n.price-cut .was{\n  position:relative;font-size:.95rem;color:color-mix(in srgb,var(--text-color) 45%,transparent);\n}\n\n.price-cut .strike{\n  position:absolute;left:0;top:50%;height:1.5px;width:0;\n  background:currentColor;transform:translateY(-50%);\n  pointer-events:none;\n}\n\n.price-cut .now{\n  font-size:1.25rem;font-weight:600;\n  opacity:0;transform:translateY(6px);\n  min-width:2.4ch;\n}\n",
    "js": "const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;\nfunction pulseTap(el) {\n  if (!el || reduce) return;\n  el.classList.remove('is-tap');\n  void el.offsetWidth;\n  el.classList.add('is-tap');\n  clearTimeout(el._tapTimer);\n  el._tapTimer = setTimeout(() => el.classList.remove('is-tap'), 260);\n}\n// Price cut — strike, then count down to the new price\nconst priceCut = document.getElementById('price-cut');\nconst PRICE_FROM = 48;\nconst PRICE_TO = 29;\nfunction runPrice() {\n  const strike = priceCut.querySelector('.strike');\n  const now = priceCut.querySelector('.now');\n  const num = priceCut.querySelector('.num');\n  strike.style.transition = 'none';\n  strike.style.width = '0';\n  now.style.transition = 'none';\n  now.style.opacity = '0';\n  now.style.transform = 'translateY(6px)';\n  num.textContent = PRICE_FROM;\n  void priceCut.offsetWidth;\n  if (reduce) {\n    strike.style.width = '100%';\n    now.style.opacity = '1';\n    now.style.transform = 'none';\n    num.textContent = PRICE_TO;\n    return;\n  }\n  strike.style.transition = 'width .35s cubic-bezier(.22,1,.36,1)';\n  strike.style.width = '100%';\n  setTimeout(() => {\n    now.style.transition = 'opacity .3s ease, transform .4s cubic-bezier(.22,1,.36,1)';\n    now.style.opacity = '1';\n    now.style.transform = 'none';\n    const t0 = performance.now();\n    const tick = (t) => {\n      const p = Math.min((t - t0) / 600, 1);\n      const eased = 1 - Math.pow(1 - p, 3);\n      num.textContent = Math.round(PRICE_FROM + (PRICE_TO - PRICE_FROM) * eased);\n      if (p < 1) requestAnimationFrame(tick);\n    };\n    requestAnimationFrame(tick);\n  }, 320);\n}\nif (priceCut) {\n  priceCut.style.cursor = 'pointer';\n  priceCut.title = 'Click to replay';\n  priceCut.addEventListener('click', runPrice);\n  runPrice();\n}\n"
  }
}