拖拽排序最容易做出的问题,不是“拖不动”,而是“拖起来很假”。

被拖元素直接瞬移,其他元素原地不动,插入位置只靠一块高亮背景提示。操作虽然能用,但用户感受不到物体之间的空间关系,也看不清自己到底会把它放在哪里。

更自然的做法,是让拖动产生一连串有因果的反馈:光标先变化,元素被抬起,插入线出现,附近的元素依次让开,松手后再一起归位。

光标与抬起

可拖拽元素悬停时使用手指光标,按下拖动后切换为抓取光标。这个反馈不需要动画,却能在操作发生之前告诉用户“这里可以拿起来”。

被拿起的元素跟随指针移动,同时离开原本的平面:

  • 横向列表中,元素浮在整行上方;
  • 纵向列表中,元素稍微向侧面偏移,并缩小到约 90%;
  • 原位置立即合拢,不再保留一个空洞。

抬起不是装饰,而是让用户始终能看见元素将要落下的区域。被拖元素不能盖住落点,否则提示再准确也没有意义。

插入线比整块高亮更清楚

落点用一条细插入线表示,而不是给目标行铺一整块背景。

横向列表使用竖线,纵向列表使用横线。线宽保持轻量,颜色约为文字色的 15%。它出现时从中间向两端展开,移动到新落点时平滑滑过去。

插入线只出现在元素之间的真实空隙里。元素回到自己的原位置时,不显示插入线,因为这时没有新的排序结果。

涟漪避让

插入线两侧的元素向外避让,离得越近的元素让得越多,也越早启动。

设 n 为元素与插入线之间的层数,紧挨着插入线的元素为 0:

1
2
位移 = A × 0.7ⁿ
延迟 = 24ms × n

A 是基准位移:图标列表约 10px,卡片约 8px。元素使用一次轻微过冲的弹簧动画,在约 0.25 秒内稳定下来。

这样一来,靠近落点的元素动作最快、位移最大;越远的元素动作越晚、幅度越小。整体会像一次推挤从落点向外扩散,而不是几十个元素同时平移。

所有让位都用 transform 完成,不触发布局重排。真正改变顺序时,再让元素进入新的位置。

放下与取消

松手后,被拖元素占据插入线所在的位置,其他元素一起弹回新的排列。

拖拽被取消时也要有完整反馈:

  • 按 Escape 取消;
  • 松开在列表外取消;
  • 被拖元素和其他元素都回到原来的位置;
  • 键盘操作也能完成排序。

开启减少动态效果后,可以只保留插入线,去掉抬起、涟漪和弹簧。功能仍然清楚,但不强制播放运动。

每种动作使用自己的曲线

拖拽过程里至少有三类动作:

  • 光标跟随手指,需要直接、低延迟;
  • 元素被拿起,需要一个小幅度的弹起;
  • 元素落下和让位,需要弹簧收敛。

如果所有属性都共用同一条 ease-out,动作会变得平面化。分别设计曲线,才能让不同动作各自表达重量和速度。

这类交互的质感,不来自更长的动画,而来自动作之间的因果关系:用户移动的是插入线,界面回应的是两侧元素的让位;用户松手,所有元素再一起完成结果。

拖拽排序示例 Prompt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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.

站内搜索

没有找到内容!