# Europeana · 调整个人展廊的展品顺序

在电脑上登录并打开自己的展廊，把鼠标移到展品上就会出现箭头形的拖动手柄。按住手柄拖到新位置，即可调整展品顺序。

[官方来源](https://www.europeana.eu/en/create-and-use-a-europeana-account)

## 相关动效 · 拖动排序

# 拖动排序

移动某项印刷任务，调整其在制作队列中的顺序。

## 试一试

拖动行左侧的手柄调整顺序，也可以点击上移和下移。

## 交互细节

拖动时，所选行随指针移动，相邻行让位。松手后确认新顺序；按 Esc 键或取消拖动时恢复原序。禁用超出列表边界的移动。排序成功后，通过状态消息向屏幕阅读器报告任务名称、原位置和新位置。

## 各平台的操作方式

- iOS · 按住左侧手柄拖至新位置，或点按上移、下移按钮。
- Android · 按住左侧手柄拖至新位置，或点按上移、下移按钮。
- PC · 拖动手柄重新排序，也可聚焦行内的上移或下移按钮并按回车。

## 适用场景

制作队列、播放列表或按优先级排列的任务。

## 实现要求

> 拖动时给目标位置腾出空间，松手确认，同时支持取消和逐项移动。顺序改变后，请让屏幕阅读器读出移动的任务和它的新位置。

## 来源与致谢

[Atlassian Design · Accessible drag and drop](<https://atlassian.design/components/pragmatic-drag-and-drop/accessibility-guidelines/>)

## 独立 HTML 示例

将以下代码保存为 HTML 文件，用浏览器打开即可离线体验。

```html
<!doctype html>
<html lang="zh-Hans"><head><script>if(new URLSearchParams(location.search).get('reduce')==='1')document.documentElement.classList.add('motion-reduced');</script><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>拖动排序 · Motion Lab</title>
<style>
*{box-sizing:border-box}html{color-scheme:light}body{margin:0;font:15px/1.5 system-ui,-apple-system,'Malgun Gothic',sans-serif;word-break:keep-all}main{margin:auto}button{font:inherit;color:inherit;cursor:pointer}button:focus-visible,[tabindex]:focus-visible{outline:3px solid #005bc6;outline-offset:2px}button:disabled{cursor:default}h1,h2,p{margin:0}h1{font-size:clamp(26px,5vw,42px);font-weight:750;letter-spacing:-.075em;line-height:1.2}h2{font-size:18px;letter-spacing:-.04em}.mono{font:600 11px/1.4 ui-monospace,Consolas,monospace;letter-spacing:.055em}.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}button{touch-action:manipulation}html.motion-reduced *,html.motion-reduced *::before,html.motion-reduced *::after{animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important;scroll-behavior:auto!important}@media(prefers-reduced-motion:reduce){*,*::before,*::after{animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important;scroll-behavior:auto!important}}

body{background:#172724;color:#f5eed9}main{width:min(100%,680px);padding:clamp(15px,4vw,36px)}.board{background:#243931;border:1px solid #667566;padding:clamp(15px,4vw,30px);box-shadow:0 8px 30px #0e1e1d62}.header{display:flex;justify-content:space-between;align-items:center;gap:10px}.header .mono{color:#c5cfb3}h1{margin:6px 0 14px}.register{display:flex;gap:3px}.register i{width:12px;height:12px;border-radius:50%;background:#dd9d51}.register i:nth-child(2){background:#7aada0}.register i:nth-child(3){background:#de8679}.queue{list-style:none;padding:0;margin:0;display:grid;gap:7px}.row{display:flex;align-items:center;gap:12px;position:relative;padding:6px 6px 6px 0;background:#f2ead2;color:#243b33;border-left:8px solid var(--band);transition:transform .22s cubic-bezier(.2,.8,.28,1);min-height:61px}.row b{font:italic 700 23px/1 Georgia,serif}.name{display:block;font-size:16px}.detail{display:block;color:#4e5849;font-size:11px}.grab{width:36px;min-height:46px;flex:none;background:transparent;border:0;color:#536254;cursor:grab;touch-action:none;font-size:19px;line-height:1}.grab:active{cursor:grabbing}.row.lift{z-index:2;box-shadow:0 8px 18px #0a181b5c;transition:none}.controls{display:flex;gap:2px;margin-left:auto}.controls button{height:44px;width:39px;border:1px solid #bec2ad;background:#f8f4e6;font-size:16px}.controls button:disabled{color:#8f9884;border-color:transparent;background:none}.foot{margin-top:13px;min-height:24px;font-size:12px;color:#d3dcc4}@media(max-width:390px){.row{gap:6px;border-left-width:5px}.grab{width:31px}.controls button{width:33px}.row b{font-size:18px}.name{font-size:14px}}

@media(pointer:coarse){.controls button,.grab{min-width:44px;min-height:44px}}
html:is([data-motion-platform="ios"],[data-motion-platform="android"]) .controls button,
html:is([data-motion-platform="ios"],[data-motion-platform="android"]) .grab{min-width:44px;min-height:44px}
</style></head><body>

<main><section class="board"><div class="header"><span class="mono">印刷顺序 · 版画工作室</span><span class="register" aria-hidden="true"><i></i><i></i><i></i></span></div><h1>印刷队列</h1><ol id="queue" class="queue" aria-label="印刷顺序"></ol><p role="status" id="status" class="foot">拖动手柄，或使用上移和下移按钮调整顺序。</p></section></main>

<script>

const items=[['田野斑点','赭色油墨','#d7a35a'],['树影','绿色油墨','#629781'],['行者之线','珊瑚红油墨','#c46f5b'],['暮色铅字','黑色油墨','#63716d']];
const queue=document.querySelector('#queue'),status=document.querySelector('#status');let drag=null;
function nodes(){return Array.from(queue.children);}
function number(){nodes().forEach((el,i)=>{el.querySelector('b').textContent=String(i+1).padStart(2,'0');el.querySelector('.up').disabled=i===0;el.querySelector('.down').disabled=i===queue.children.length-1;});}
function commit(row,from,to,origin){
  const order=nodes(),before=new Map(order.map(el=>[el,el.getBoundingClientRect().top]));
  order.splice(from,1);order.splice(to,0,row);queue.replaceChildren(...order);number();
  const reduce=document.documentElement.classList.contains('motion-reduced')||matchMedia('(prefers-reduced-motion: reduce)').matches;
  if(!reduce)order.forEach(el=>{const offset=before.get(el)-el.getBoundingClientRect().top;if(offset)el.animate([{transform:'translateY('+offset+'px)'},{transform:'none'}],{duration:210,easing:'ease-out'});});
  (origin.disabled?row.querySelector('.grab'):origin).focus({preventScroll:true});
  status.textContent=row.querySelector('.name').textContent+' · 已从第 '+(from+1)+' 位移至第 '+(to+1)+' 位。';
}
function cancel(e,accept=false){
  if(!drag||(e&&e.pointerId!==drag.id))return;
  const d=drag;drag=null;
  d.row.classList.remove('lift');nodes().forEach(el=>el.style.removeProperty('transform'));
  if(d.grab.hasPointerCapture(d.id))d.grab.releasePointerCapture(d.id);
  if(accept&&d.from!==d.to)commit(d.row,d.from,d.to,d.grab);
  else if(d.moved){status.textContent=accept?'顺序未改变。':'已取消移动。';d.grab.focus({preventScroll:true});}
}
for(const [title,ink,band] of items){
  const row=document.createElement('li');row.className='row';row.style.setProperty('--band',band);
  row.innerHTML='<button type="button" class="grab">⠿</button><b aria-hidden="true"></b><div><strong class="name"></strong><small class="detail"></small></div><div class="controls"><button class="up" type="button">↑</button><button class="down" type="button">↓</button></div>';
  row.querySelector('.name').textContent=title;row.querySelector('.detail').textContent=ink;
  const grab=row.querySelector('.grab');grab.setAttribute('aria-label',title+' 拖动手柄');grab.setAttribute('aria-describedby','status');
  for(const [cls,delta] of [['up',-1],['down',1]]){
    const button=row.querySelector('.'+cls);button.setAttribute('aria-label',title+(delta<0?' 上移':' 下移'));
    button.addEventListener('click',()=>{if(drag)return;const i=nodes().indexOf(row),to=i+delta;if(to>=0&&to<queue.children.length)commit(row,i,to,button);});
  }
  grab.addEventListener('keydown',e=>{if(drag)return;const delta=e.key==='ArrowDown'?1:e.key==='ArrowUp'?-1:0;if(delta){e.preventDefault();const i=nodes().indexOf(row),to=i+delta;if(to>=0&&to<queue.children.length)commit(row,i,to,grab);}});
  grab.addEventListener('click',e=>{if(e.detail===0)status.textContent='按方向键，或使用行内的移动按钮。';});
  grab.addEventListener('pointerdown',e=>{if(drag||e.button!==0||!e.isPrimary)return;const positions=nodes().map(el=>el.offsetTop),from=nodes().indexOf(row);drag={row,grab,id:e.pointerId,y:e.clientY,from,to:from,positions,moved:false};grab.setPointerCapture(e.pointerId);});
  grab.addEventListener('pointermove',e=>{if(!drag||drag.id!==e.pointerId||drag.row!==row)return;const d=drag,dy=e.clientY-d.y;if(!d.moved&&Math.abs(dy)<3)return;d.moved=true;row.classList.add('lift');const offset=Math.max(d.positions[0]-d.positions[d.from],Math.min(dy,d.positions.at(-1)-d.positions[d.from]));const top=d.positions[d.from]+offset;
    d.to=d.positions.reduce((best,pos,i)=>Math.abs(pos-top)<Math.abs(d.positions[best]-top)?i:best,d.from);
    nodes().forEach((el,i)=>{let shift=0;if(i===d.from)shift=offset;else if(i>d.from&&i<=d.to)shift=d.positions[i-1]-d.positions[i];else if(i<d.from&&i>=d.to)shift=d.positions[i+1]-d.positions[i];el.style.transform='translateY('+shift+'px)';});
  });
  grab.addEventListener('pointerup',e=>cancel(e,true));grab.addEventListener('pointercancel',e=>cancel(e));grab.addEventListener('lostpointercapture',e=>cancel(e));
  queue.append(row);
}
document.addEventListener('keydown',e=>{if(e.key==='Escape'&&drag){e.preventDefault();cancel(null);}});
number();

</script></body></html>
```
