Card Swap (Stack Shuffle) new 卡片交换(叠卡切换) web

标本可交互,可以直接操作。

Anatomy — every part, named解剖 —— 每个部件的名字

  1. 1 Depth slots层级位置 transform + z-index

    Each depth has a fixed offset, scale and brightness so the cards behind peek out.

    每一层有固定的偏移、缩放和亮度,后面的卡露出边缘。

    Prompt fragmentPrompt 片段

    deeper cards offset up and right, smaller and dimmer

    越往后的卡越往右上偏、越小越暗

  2. 2 Drag and lean拖动与倾斜 pointer capture

    The top card follows the pointer and leans in the direction it moves.

    顶部卡片跟随指针,并朝移动方向倾斜。

    Prompt fragmentPrompt 片段

    the top card following the pointer and rotating with horizontal distance

    顶部卡片跟随指针,按水平距离旋转

  3. 3 Throw threshold甩出阈值 distance or velocity

    Past 60px or a quick flick it swaps; otherwise it springs back.

    超过 60px 或快速甩动就切换,否则弹回。

    Prompt fragmentPrompt 片段

    swap past 60px or a fast flick, otherwise spring back

    超过 60px 或快速甩动就切换,否则弹回

  4. 4 Tuck behind插到后面 order rotation

    The card goes out first, then drops to the back while the rest move up.

    卡片先飞出,再落到最后一层,其余卡片依次上移。

    Prompt fragmentPrompt 片段

    throw out first, then drop to the back slot while the others move up

    先甩出,再落到最后一层,其余卡片上移

Prompt — paste into your agentPrompt —— 直接粘贴给你的代理

Build a card swap: stack 4 photo cards so each deeper card is offset 13px right and 10px up, scaled down 5.5% and slightly darker, with z-index by depth. The top card can be dragged (pointer capture, it follows the pointer and rotates by 0.08° per px); on release, if it moved more than 60px or was flicked faster than 0.6px/ms, run two phases: first throw it 170px in the drag direction with a little rotation (about 230ms), then rotate the order array (top to bottom), drop its z-index and let every card transition to its new slot with a slight overshoot. Otherwise spring it back. A click swaps too. Ignore input while a swap is running; honour prefers-reduced-motion by skipping the throw.

做一个卡片交换:4 张照片卡叠放,越往后的卡向右偏 13px、向上偏 10px、缩小 5.5% 并稍微变暗,z-index 按层级排列。最上面一张可以拖动(指针捕获,卡片跟随指针,每移动 1px 旋转 0.08°);松手时如果移动超过 60px 或甩动速度超过 0.6px/ms,分两段执行:先沿拖动方向把卡甩出 170px 并带一点旋转(约 230ms),再把顺序数组从头移到尾、降低它的 z-index,让每张卡带轻微回弹过渡到新位置;否则弹回原位。单击也能切换。切换动画进行中忽略输入;prefers-reduced-motion 时跳过甩出动画。

Debug prompt — when it misbehaves调试 Prompt —— 当它不听话时

Debug my card swap. Check that the order array is the single source of truth and the DOM transforms are derived from it; the thrown card's z-index drops only after it has cleared the stack (or it will cut through the others); the drag sets transition: none and restores it on release; pointer capture is taken so fast drags do not lose the card; clicks are not counted as tiny drags that spring back; a second swap cannot start while one is animating; and slots use transforms, not top/left, so the animation stays on the compositor. The symptom:

调试我的卡片交换。检查:顺序数组是否是唯一的数据来源,DOM 的位移都由它推导;被甩出的卡是否在离开卡堆后才降低 z-index(否则会从其它卡中间穿过);拖动时是否设了 transition: none,松手后恢复;是否用了指针捕获,快速拖动时不会丢卡;单击是否被当成很小的拖动而弹回;动画进行中能否开始第二次切换;位置是否用 transform 而不是 top/left,保证动画在合成层上进行。症状是:

In code代码里叫什么

Framework框架Symbol符号Note说明
CSS transform: translate() scale() + z-index each depth slot is a fixed offset, scale and stacking order每一层是固定的位移、缩放和层级
JS order.push(order.shift()) the data change is a rotation of the order array数据上就是把顺序数组转一格
Web PointerEvent + setPointerCapture drag the top card and keep receiving moves outside it拖动顶部卡片,指针移出卡片也能继续收到事件
Motion drag + onDragEnd(velocity) the same throw threshold in Framer MotionFramer Motion 里同样的甩出阈值写法

See also相关词条

我的参考集

组合知名网站、UI 元素、视觉风格和平面设计案例,导出给 AI。

你的下一份设计,从这里开始。

在任意案例旁点击「加入参考」,就能把品牌、组件、风格和平面设计案例组合成一份 AI 设计说明。

搜索参考库Search the library

输入关键词,搜索所有参考。