005 Drag Ripple
带避让动效的拖拽排序
拖拽排序的光标、落点插入线和两侧元素的避让动效,适用于列表、看板和横向排列。
很多拖拽排序在拖动时其余元素不动,松手后列表才突然重排,落在了哪两项之间,只能松手后再检查。下面五条让用户在松手前就看到结果:
- 光标:所有可拖动的元素都要设置。悬停时显示手形,拖动时显示抓取手形,用户按下之前就知道它可以拖。
- 拖动的元素:跟随指针,同时避开落点,不挡住插入线。横向排列中向上浮起;纵向列表中移到一侧,并缩小到约 90%。它原来的位置随之合拢。
- 插入线:用来标出落点,是一条很淡的细线,颜色约为文字颜色的 15%;横排时竖直,列表中水平;出现时从中间向两端展开,落点改变时平移过去,元素原来的位置上不显示。
- 避让:插入线两侧的元素向外让开,离得越近,让得越多、动得越早:位移 = 10px × 0.7ⁿ,延迟 = 24ms × n,n 是与插入线相隔的元素数,紧挨着的为 0。图标从 10px 起,卡片从 8px 起。
- 放下与取消:松手后,元素进入空位,其余元素以弹簧动效移到新位置;按 Esc 或在列表外松手视为取消,所有元素回到原位。
另外,只用 transform 移动元素,不改变布局;排序也要能用键盘完成;开启「减弱动态效果」时,只保留插入线。
参数
- 位移
- 图标 10px;卡片 8px;每隔一个元素乘以 0.7
- 延迟
- 每隔一个元素增加 24ms
- 弹簧
- 几乎无回弹;约 0.25s 停止
- 插入线
- 文字颜色的约 15%
附带的 Prompt 会复用项目已有的拖拽逻辑,把这套效果加到你指定的列表、行和程序坞上。
Make drag-to-reorder in my product feel like this. Apply it to the lists, rows and docks I name, and reuse any drag helper the project already has. 1. Cursor: a pointing hand over anything draggable, a grabbing hand while dragging. 2. Lift: the picked item follows the pointer, raised off the list so it never hides where it will land: above a horizontal row, or pulled aside and shrunk to about 90% in a vertical list. Its old slot closes up. 3. Drop hint: a faint, thin line in the gap where it will land (vertical in a row, horizontal in a list), about 15% of the text color. It grows from its middle when it appears and glides to each new gap. No line over the item's own slot. 4. Ripple: items on both sides of the line lean away from it. Counting n from the line (0 = the item touching it), item n moves A x 0.7^n (A is about 10px for icons, 8px for cards) and starts 24ms x n later, on a quick spring that barely overshoots and settles in about 0.25s. Nearer items move sooner and further, so the push spreads out like a ripple. 5. Drop: the item takes the gap and every item springs into its new place. Escape or dropping outside the list cancels, and everything springs back. 6. Give each motion its own curve (hand-like for the pointer, a small pop for the lift, springs for settling) instead of one ease-out everywhere. Move things with transforms, not layout. Let the keyboard reorder too, and with reduced motion keep only the line.





















