# Spotify · 플레이리스트 순서 직접 정하기

데스크톱 앱의 라이브러리에서 플레이리스트만 표시한 뒤 사용자 지정 정렬을 고릅니다. 목록 하나를 끌어 놓으면 다른 기기에서도 그 순서로 표시됩니다.

[공식 원문](https://support.spotify.com/us/article/sort-and-filter/)

## 관련 모션 · 드래그 순서 변경

# 드래그 순서 변경 (Reorder List)

인쇄 대기열에서 판을 다른 자리에 놓으면 대기 순서가 바뀝니다.

## 체험 방법

원하는 행의 손잡이를 끌어 놓으세요. 각 행의 위·아래 버튼으로도 자리를 바꿀 수 있습니다.

## 재현 기준

끌고 있는 행은 포인터를 따라가고 이웃 행은 목표 위치를 비켜줍니다. 놓으면 순서를 확정하고, Escape 또는 취소 이벤트에는 시작 순서를 복구합니다. 대체 버튼은 경계에서 이동을 막고, 이동한 항목과 앞뒤 순번을 공지합니다.

## 기기별 조작

- iOS · 행 왼쪽 손잡이를 누른 채 다른 자리까지 끌어 놓으세요. 위·아래 버튼으로도 이동합니다.
- Android · 행 왼쪽 손잡이를 끌어 원하는 순서에 놓거나 위·아래 버튼을 누르세요.
- PC · 손잡이를 끌어 놓거나, 각 행의 위·아래 버튼에 초점을 두고 Enter로 옮기세요.

## 적용할 때

재생 목록, 우선순위 또는 작업 대기열의 순서를 직접 편집할 때.

## 그대로 보낼 요청

> 손잡이를 끌어 대기 순서를 바꾸고 드래그 없이도 위·아래 버튼으로 같은 순서를 설정하게 해줘.

## 참고한 동작

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

## 독립 실행 코드

아래 전체 코드를 HTML로 저장해 브라우저에서 엽니다.

```html
<!doctype html>
<html lang="ko"><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">PRESS ORDER / 인쇄 작업실</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>
```

