-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path08-prototype-interaction.html
More file actions
388 lines (369 loc) · 10.4 KB
/
Copy path08-prototype-interaction.html
File metadata and controls
388 lines (369 loc) · 10.4 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Acme — 侧边栏拖拽排序</title>
<style>
:root {
--ivory: #FAF9F5;
--slate: #141413;
--clay: #D97757;
--oat: #E3DACC;
--olive: #788C5D;
--gray-50: #F0EEE6;
--gray-200: #D1CFC5;
--gray-500: #87867F;
--gray-800: #3D3D3A;
--white: #ffffff;
--serif: ui-serif, Georgia, "Times New Roman", serif;
--sans: system-ui, -apple-system, "Segoe UI", sans-serif;
--mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
background: var(--ivory);
color: var(--slate);
font-family: var(--sans);
font-size: 14px;
line-height: 1.55;
}
.wrap {
max-width: 1040px;
margin: 0 auto;
padding: 48px 32px 64px;
}
header { margin-bottom: 28px; }
.eyebrow {
font-family: var(--mono);
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--gray-500);
}
h1 {
font-family: var(--serif);
font-weight: 500;
font-size: 30px;
letter-spacing: -0.01em;
margin: 6px 0 4px;
}
.sub {
color: var(--gray-500);
max-width: 600px;
}
code.inline {
font-family: var(--mono);
font-size: 12px;
background: var(--gray-50);
border: 1.5px solid var(--gray-200);
padding: 1px 5px;
border-radius: 4px;
}
/* ---------- layout ---------- */
.bench {
display: grid;
grid-template-columns: 300px 1fr;
gap: 28px;
align-items: start;
}
/* ---------- sidebar mock ---------- */
.sidebar {
width: 260px;
background: var(--white);
border: 1.5px solid var(--gray-200);
border-radius: 12px;
padding: 14px 10px;
}
.sidebar-title {
font-family: var(--mono);
font-size: 10px;
letter-spacing: 0.1em;
text-transform: uppercase;
color: var(--gray-500);
padding: 4px 10px 10px;
}
.list {
position: relative;
list-style: none;
margin: 0;
padding: 0;
}
.item {
display: flex;
align-items: center;
gap: 10px;
padding: 9px 10px;
margin: 2px 0;
border-radius: 8px;
background: var(--white);
cursor: grab;
user-select: none;
transition: background 120ms linear, transform 120ms ease-out, opacity 120ms linear;
}
.item:hover { background: var(--gray-50); }
.item:hover .grip i { background: var(--gray-800); }
.item.dragging {
opacity: 0.35;
transform: rotate(2deg);
background: var(--gray-50);
cursor: grabbing;
}
.item .label { font-size: 14px; color: var(--slate); }
.item .count {
margin-left: auto;
font-family: var(--mono);
font-size: 11px;
color: var(--gray-500);
}
/* grip: 2 × 3 dot grid, pure css */
.grip {
flex: none;
width: 10px;
height: 16px;
display: grid;
grid-template-columns: repeat(2, 3px);
grid-template-rows: repeat(3, 3px);
gap: 3px;
align-content: center;
}
.grip i {
width: 3px;
height: 3px;
border-radius: 50%;
background: var(--gray-200);
transition: background 120ms linear;
}
/* drop indicator line */
.indicator {
position: absolute;
left: 6px;
right: 6px;
height: 2px;
background: var(--clay);
border-radius: 2px;
pointer-events: none;
display: none;
}
.indicator::before {
content: "";
position: absolute;
left: -5px;
top: -3px;
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--clay);
}
.indicator.on { display: block; }
/* ---------- annotation panel ---------- */
.notes {
background: var(--white);
border: 1.5px solid var(--gray-200);
border-radius: 12px;
padding: 22px 24px;
}
.notes h2 {
font-family: var(--serif);
font-weight: 500;
font-size: 18px;
margin: 0 0 6px;
}
.notes .lede {
color: var(--gray-500);
font-size: 13px;
margin: 0 0 16px;
}
.notes ul {
list-style: none;
margin: 0;
padding: 0;
}
.notes li {
position: relative;
padding: 10px 0 10px 22px;
border-top: 1.5px solid var(--gray-50);
font-size: 13px;
color: var(--gray-800);
}
.notes li:first-child { border-top: none; }
.notes li::before {
content: "";
position: absolute;
left: 4px;
top: 16px;
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--clay);
}
.notes li b { color: var(--slate); font-weight: 600; }
/* ---------- open questions ---------- */
.questions {
margin-top: 28px;
background: var(--oat);
border: 1.5px solid var(--gray-200);
border-radius: 12px;
padding: 20px 24px;
}
.questions h2 {
font-family: var(--serif);
font-weight: 500;
font-size: 17px;
margin: 0 0 12px;
}
.questions ol {
margin: 0;
padding-left: 20px;
}
.questions li {
font-size: 13px;
color: var(--gray-800);
padding: 4px 0;
}
.questions li::marker {
font-family: var(--mono);
color: var(--olive);
font-weight: 600;
}
.footnote {
margin-top: 18px;
font-family: var(--mono);
font-size: 11px;
color: var(--gray-500);
}
</style>
</head>
<body>
<div class="wrap">
<header>
<div class="eyebrow">Acme / 原型 / 交互</div>
<h1>侧边栏拖拽排序</h1>
<p class="sub">
一次性 HTML,让我们 <em>feel</em> 排序效果,然后再移植到 React。 原生 <code class="inline">dragstart / dragover / drop</code>,
约 40 行 JS,无依赖库。按住圆点拖动行即可。
</p>
</header>
<div class="bench">
<div>
<nav class="sidebar">
<div class="sidebar-title">视图</div>
<ul class="list" id="list">
<li class="item" draggable="true">
<span class="grip"><i></i><i></i><i></i><i></i><i></i><i></i></span>
<span class="label">收件箱</span>
<span class="count">14</span>
</li>
<li class="item" draggable="true">
<span class="grip"><i></i><i></i><i></i><i></i><i></i><i></i></span>
<span class="label">今天</span>
<span class="count">3</span>
</li>
<li class="item" draggable="true">
<span class="grip"><i></i><i></i><i></i><i></i><i></i><i></i></span>
<span class="label">即将到来</span>
<span class="count">21</span>
</li>
<li class="item" draggable="true">
<span class="grip"><i></i><i></i><i></i><i></i><i></i><i></i></span>
<span class="label">项目</span>
<span class="count">8</span>
</li>
<li class="item" draggable="true">
<span class="grip"><i></i><i></i><i></i><i></i><i></i><i></i></span>
<span class="label">归档</span>
<span class="count"></span>
</li>
<li class="item" draggable="true">
<span class="grip"><i></i><i></i><i></i><i></i><i></i><i></i></span>
<span class="label">回收站</span>
<span class="count"></span>
</li>
<div class="indicator" id="indicator"></div>
</ul>
</nav>
<p class="footnote">排序仅保持在 DOM 中,刷新即重置。</p>
</div>
<div>
<section class="notes">
<h2>你在感受的是什么</h2>
<p class="lede">内置在这个原型中的设计决策,方便你提出异议。</p>
<ul>
<li>
<b>放置指示器吸附到最近的间隙</b>,不是跟随原始光标 Y 坐标。只有跨过一行的中点时才移动,感觉更果断,不抖。
</li>
<li>
<b>拖动的行留在原位,35% 透明度</b>,带 2° 倾斜。幽灵留在列表中保持了你对起始位置的感知,倾斜表达“抬起”的意思。
</li>
<li>
<b>拖拽圆点是视觉提示,但整行都可拖。</b>悬停时圆点变深,教会用户手势,不强迫精确点击小目标。
</li>
<li>
<b>没有自动滚动,没有放置动画。</b>故意省略,便于评估核心手感。说一声,下一轮就加。
</li>
</ul>
</section>
<section class="questions">
<h2>待讨论问题</h2>
<ol>
<li><b>回收站</b>(可能还有<b>归档</b>)要不要固定在底部,不参与排序?</li>
<li>放下时行要<b>滑动</b>到新位置,还是直接跳转就行?</li>
<li>键盘路径:用 <code class="inline">Alt + Arrow</code> 移动聚焦行,第一版够不够?</li>
</ol>
</section>
</div>
</div>
</div>
<script>
var list = document.getElementById('list');
var indicator = document.getElementById('indicator');
var dragging = null;
var dropBefore = null; // node to insert before, or null = append
list.addEventListener('dragstart', function (e) {
var item = e.target.closest('.item');
if (!item) return;
dragging = item;
item.classList.add('dragging');
e.dataTransfer.effectAllowed = 'move';
e.dataTransfer.setData('text/plain', '');
});
list.addEventListener('dragover', function (e) {
if (!dragging) return;
e.preventDefault();
var siblings = Array.prototype.filter.call(
list.children,
function (el) { return el.classList && el.classList.contains('item'); }
);
dropBefore = null;
for (var i = 0; i < siblings.length; i++) {
var r = siblings[i].getBoundingClientRect();
if (e.clientY < r.top + r.height / 2) { dropBefore = siblings[i]; break; }
}
var listRect = list.getBoundingClientRect();
var edge = dropBefore
? dropBefore.getBoundingClientRect().top
: siblings[siblings.length - 1].getBoundingClientRect().bottom;
indicator.style.top = (edge - listRect.top - 1) + 'px';
indicator.classList.add('on');
});
list.addEventListener('drop', function (e) {
e.preventDefault();
if (!dragging) return;
if (dropBefore) list.insertBefore(dragging, dropBefore);
else list.insertBefore(dragging, indicator);
cleanup();
});
list.addEventListener('dragleave', function (e) {
if (!list.contains(e.relatedTarget)) indicator.classList.remove('on');
});
document.addEventListener('dragend', cleanup);
function cleanup() {
if (dragging) dragging.classList.remove('dragging');
dragging = null;
dropBefore = null;
indicator.classList.remove('on');
}
</script>
</body>
</html>