01Whole-Object Drag Move, No Handle Needed
Pressing and dragging anywhere on a selected object's body moves it and its bounding selection box together along the pointer, stopping exactly where it's released.
Best forRepositioning stickers or icons on a canvas
applyTransformonPointerMoveeaseOutCubic

<main class="stage">
<div class="scene is-demo" id="scene">
<div class="grid" aria-hidden="true"></div>
<div class="draggable" id="draggable" tabindex="0" aria-label="Drag to move">
<div class="selectBox">
<div class="subjectShape"></div>
</div>
</div>
<div class="readout" id="readout" aria-hidden="true">X <span id="rx">0</span> · Y <span id="ry">0</span></div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 변수 3개
$duration: $dur-enter;
$easing: $ease-out;
$color: $subject-lilac;
// 계산 겹: index.html 의 applyTransform() 이 포인터 델타를 matrix(1,0,0,1,tx,ty) 순수 이동 행렬로
// 그대로 굳혀 style.transform 에 넣는다 — CSS 트랜지션이 아니라 매 프레임 산술로 값을 만든다.
@include stage($stage-ink);
.scene {
position: relative;
width: 320px;
height: 180px;
border-radius: $r-card;
overflow: hidden;
box-shadow: $shadow-raised;
background: linear-gradient(160deg, #201c2c, $stage-ink 70%);
}
.grid {
position: absolute;
inset: 0;
background-image:
linear-gradient(rgba(255, 255, 255, .05) 1px, transparent 1px),
linear-gradient(90deg, rgba(255, 255, 255, .05) 1px, transparent 1px);
background-size: 20px 20px;
}
.draggable {
position: absolute;
top: 50%;
left: 50%;
margin-top: -34px;
margin-left: -48px;
width: 96px;
height: 68px;
cursor: grab;
touch-action: none;
will-change: transform;
&.isDragging { cursor: grabbing; }
&:focus-visible .selectBox { outline: 2px solid $color; outline-offset: 3px; }
}
.selectBox {
position: relative;
width: 100%;
height: 100%;
border: 1px dashed rgba($subject-cream, .4);
border-radius: $r-sm;
box-sizing: border-box;
display: grid;
place-items: center;
}
.subjectShape {
width: 72px;
height: 48px;
border-radius: $r-sm;
background: linear-gradient(135deg, $subject-pink, $subject-lilac);
box-shadow: $shadow-press;
}
.readout {
position: absolute;
left: $sp-3;
bottom: $sp-3;
padding: $sp-1 $sp-2;
border-radius: $r-pill;
background: rgba(#050409, .5);
color: rgba($subject-cream, .82);
font-size: 10px;
font-variant-numeric: tabular-nums;
letter-spacing: .02em;
}
@media (max-width: 340px) {
.scene { width: 220px; height: 124px; }
.draggable { width: 68px; height: 48px; margin-top: -24px; margin-left: -34px; }
.subjectShape { width: 52px; height: 34px; }
.readout { font-size: 9px; }
}
@media (prefers-reduced-motion: reduce) {
// 실사용 경로 적용 — 드래그·키보드 이동은 index.html 이 트윈 없이 즉시 반영한다.
// scss 만: 포커스 아웃라인 전환만 꺼서 잔여 트랜지션을 없앤다.
.draggable { transition: none; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #17141a;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.scene {
position: relative;
width: 320px;
height: 180px;
border-radius: 16px;
overflow: hidden;
box-shadow: 0 14px 24px rgba(23, 20, 26, 0.32);
background: linear-gradient(160deg, #201c2c, #17141a 70%);
}
.grid {
position: absolute;
inset: 0;
background-image: linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
background-size: 20px 20px;
}
.draggable {
position: absolute;
top: 50%;
left: 50%;
margin-top: -34px;
margin-left: -48px;
width: 96px;
height: 68px;
cursor: grab;
touch-action: none;
will-change: transform;
}
.draggable.isDragging {
cursor: grabbing;
}
.draggable:focus-visible .selectBox {
outline: 2px solid #b9a0ff;
outline-offset: 3px;
}
.selectBox {
position: relative;
width: 100%;
height: 100%;
border: 1px dashed rgba(255, 247, 230, 0.4);
border-radius: 8px;
box-sizing: border-box;
display: grid;
place-items: center;
}
.subjectShape {
width: 72px;
height: 48px;
border-radius: 8px;
background: linear-gradient(135deg, #ff9ebb, #b9a0ff);
box-shadow: 0 6px 12px rgba(23, 20, 26, 0.32);
}
.readout {
position: absolute;
left: 12px;
bottom: 12px;
padding: 4px 8px;
border-radius: 999px;
background: rgba(5, 4, 9, 0.5);
color: rgba(255, 247, 230, 0.82);
font-size: 10px;
font-variant-numeric: tabular-nums;
letter-spacing: 0.02em;
}
@media (max-width: 340px) {
.scene {
width: 220px;
height: 124px;
}
.draggable {
width: 68px;
height: 48px;
margin-top: -24px;
margin-left: -34px;
}
.subjectShape {
width: 52px;
height: 34px;
}
.readout {
font-size: 9px;
}
}
@media (prefers-reduced-motion: reduce) {
.draggable {
transition: none;
}
}(function () {
var WAYPOINTS = [
{ x: 0, y: 0 },
{ x: 92, y: -38 },
{ x: -70, y: 30 },
{ x: 0, y: 0 }
];
var HOP_MS = 640;
var HOLD_MS = 380;
var scene = document.getElementById('scene');
var el = document.getElementById('draggable');
var rx = document.getElementById('rx');
var ry = document.getElementById('ry');
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
var tx = 0, ty = 0;
var dragging = false;
var startX = 0, startY = 0, originTx = 0, originTy = 0;
var timers = [];
function clamp(v, lo, hi) { return Math.min(hi, Math.max(lo, v)); }
function easeOutCubic(t) { return 1 - Math.pow(1 - t, 3); }
// 포인터 델타 → translate 행렬. matrix(1,0,0,1,tx,ty) 가 곧 순수 이동 행렬이다.
function applyTransform(nx, ny) {
tx = nx; ty = ny;
el.style.transform = 'matrix(1,0,0,1,' + tx.toFixed(1) + ',' + ty.toFixed(1) + ')';
rx.textContent = Math.round(tx);
ry.textContent = Math.round(ty);
}
function human() {
if (scene.classList.contains('is-demo')) {
scene.classList.remove('is-demo');
timers.forEach(function (t) { clearTimeout(t); clearInterval(t); });
timers = [];
}
}
function onPointerDown(e) {
human();
dragging = true;
el.setPointerCapture(e.pointerId);
startX = e.clientX; startY = e.clientY;
originTx = tx; originTy = ty;
el.classList.add('isDragging');
}
function onPointerMove(e) {
if (!dragging) return;
var dx = e.clientX - startX;
var dy = e.clientY - startY;
applyTransform(clamp(originTx + dx, -110, 110), clamp(originTy + dy, -55, 55));
}
function onPointerUp(e) {
if (!dragging) return;
dragging = false;
el.classList.remove('isDragging');
try { el.releasePointerCapture(e.pointerId); } catch (err) {}
}
function onKeydown(e) {
var step = e.shiftKey ? 10 : 1;
if (e.key === 'ArrowLeft') { human(); applyTransform(clamp(tx - step, -110, 110), ty); e.preventDefault(); }
else if (e.key === 'ArrowRight') { human(); applyTransform(clamp(tx + step, -110, 110), ty); e.preventDefault(); }
else if (e.key === 'ArrowUp') { human(); applyTransform(tx, clamp(ty - step, -55, 55)); e.preventDefault(); }
else if (e.key === 'ArrowDown') { human(); applyTransform(tx, clamp(ty + step, -55, 55)); e.preventDefault(); }
}
el.addEventListener('pointerdown', onPointerDown);
el.addEventListener('pointermove', onPointerMove);
el.addEventListener('pointerup', onPointerUp);
el.addEventListener('pointercancel', onPointerUp);
el.addEventListener('keydown', onKeydown);
// reduce: 실사용 경로 적용 — 포인터·키보드 이동은 위 리스너가 그대로 처리한다(트윈 없이 즉시 반영).
// 아래 hopTo()·cycle() 은 시연 게이트만 — reduce 에서는 돌지 않는다.
function hopTo(target, onDone) {
var fromTx = tx, fromTy = ty;
var start = performance.now();
function frame(now) {
if (!scene.classList.contains('is-demo')) return;
var p = clamp((now - start) / HOP_MS, 0, 1);
var e = easeOutCubic(p);
applyTransform(fromTx + (target.x - fromTx) * e, fromTy + (target.y - fromTy) * e);
if (p < 1) requestAnimationFrame(frame);
else if (onDone) onDone();
}
requestAnimationFrame(frame);
}
function cycle(i) {
if (!scene.classList.contains('is-demo')) return;
var next = WAYPOINTS[i % WAYPOINTS.length];
hopTo(next, function () {
timers.push(setTimeout(function () { cycle(i + 1); }, HOLD_MS));
});
}
if (!reduce) {
cycle(1);
}
})();import { useEffect, useRef } from 'react';
import styles from './XfDragMove.module.scss';
const STEP_PX = 1; // 방향키 한 번의 기본 이동량
const STEP_PX_SHIFT = 10; // Shift + 방향키
const HOP_MS = 620;
const HOLD_MS = 360;
const WAYPOINTS = [
{ x: 0, y: 0 }, { x: 92, y: -38 }, { x: -70, y: 30 }, { x: 0, y: 0 }
];
export default function XfDragMove() {
const sceneRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const scene0 = sceneRef.current;
if (!scene0) return undefined;
const scene = scene0;
const draggable0 = scene.querySelector<HTMLDivElement>('.' + styles.draggable);
const rx0 = scene.querySelector<HTMLSpanElement>('#rx');
const ry0 = scene.querySelector<HTMLSpanElement>('#ry');
if (!draggable0 || !rx0 || !ry0) return undefined;
const draggable = draggable0;
const rx = rx0;
const ry = ry0;
const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
let tx = 0, ty = 0;
let dragging = false;
let startX = 0, startY = 0, originTx = 0, originTy = 0;
let rafId = 0;
let timers: number[] = [];
function clamp(v: number, lo: number, hi: number) { return Math.min(hi, Math.max(lo, v)); }
function easeOutCubic(t: number) { return 1 - Math.pow(1 - t, 3); }
// 포인터 델타 → translate 행렬. matrix(1,0,0,1,tx,ty) 가 곧 순수 이동 행렬이다.
function applyTransform(nx: number, ny: number) {
tx = nx; ty = ny;
draggable.style.transform = 'matrix(1,0,0,1,' + tx.toFixed(1) + ',' + ty.toFixed(1) + ')';
rx.textContent = String(Math.round(tx));
ry.textContent = String(Math.round(ty));
}
function human() {
if (scene.classList.contains(styles['is-demo'])) {
scene.classList.remove(styles['is-demo']);
timers.forEach((t) => window.clearTimeout(t));
timers = [];
}
}
function onPointerDown(e: PointerEvent) {
human();
dragging = true;
draggable.setPointerCapture(e.pointerId);
startX = e.clientX; startY = e.clientY;
originTx = tx; originTy = ty;
}
function onPointerMove(e: PointerEvent) {
if (!dragging) return;
applyTransform(originTx + (e.clientX - startX), originTy + (e.clientY - startY));
}
function endDrag(e: PointerEvent) {
if (!dragging) return;
dragging = false;
try { draggable.releasePointerCapture(e.pointerId); } catch { /* 캡처가 이미 풀린 경우 */ }
}
function onKeyDown(e: KeyboardEvent) {
const step = e.shiftKey ? STEP_PX_SHIFT : STEP_PX;
if (e.key === 'ArrowLeft') { human(); applyTransform(tx - step, ty); e.preventDefault(); }
else if (e.key === 'ArrowRight') { human(); applyTransform(tx + step, ty); e.preventDefault(); }
else if (e.key === 'ArrowUp') { human(); applyTransform(tx, ty - step); e.preventDefault(); }
else if (e.key === 'ArrowDown') { human(); applyTransform(tx, ty + step); e.preventDefault(); }
}
draggable.addEventListener('pointerdown', onPointerDown);
draggable.addEventListener('pointermove', onPointerMove);
draggable.addEventListener('pointerup', endDrag);
draggable.addEventListener('pointercancel', endDrag);
draggable.addEventListener('keydown', onKeyDown);
// reduce: 실사용 경로 적용 — 드래그·키보드는 위에서 즉시 반영한다.
// 아래 자동 루프는 시연 게이트만 — reduce 에서는 돌지 않는다.
function hopTo(target: { x: number; y: number }, onDone: () => void) {
const fromX = tx, fromY = ty;
const start = performance.now();
function frame(now: number) {
if (!scene.classList.contains(styles['is-demo'])) return;
const p = clamp((now - start) / HOP_MS, 0, 1);
const e = easeOutCubic(p);
applyTransform(fromX + (target.x - fromX) * e, fromY + (target.y - fromY) * e);
if (p < 1) rafId = requestAnimationFrame(frame);
else onDone();
}
rafId = requestAnimationFrame(frame);
}
function cycle(i: number) {
if (!scene.classList.contains(styles['is-demo'])) return;
const target = WAYPOINTS[i % WAYPOINTS.length];
hopTo(target, () => {
timers.push(window.setTimeout(() => cycle(i + 1), HOLD_MS));
});
}
applyTransform(0, 0);
if (!reduce) {
cycle(1);
}
return () => {
draggable.removeEventListener('pointerdown', onPointerDown);
draggable.removeEventListener('pointermove', onPointerMove);
draggable.removeEventListener('pointerup', endDrag);
draggable.removeEventListener('pointercancel', endDrag);
draggable.removeEventListener('keydown', onKeyDown);
timers.forEach((t) => window.clearTimeout(t));
cancelAnimationFrame(rafId);
};
}, []);
return (
<main className={styles.stage}>
<div className={styles.scene + ' ' + styles['is-demo']} ref={sceneRef}>
<div
className={styles.draggable}
tabIndex={0}
aria-label="드래그해서 이동"
>
<span className={styles.selectBox} aria-hidden="true"></span>
<span className={styles.subjectShape} aria-hidden="true"></span>
</div>
<div className={styles.readout} aria-hidden="true">X <span id="rx">0</span> · Y <span id="ry">0</span></div>
</div>
</main>
);
}01 Whole-Object Drag Move, No Handle Needed — Measured area 11.417% · moving frames 14/23Original by GODRICH · SCSS and React ship in the zip · Resize Handle UI — 9 Free-Transform Patterns
The post this demo lives in
Resize Handle UI — 9 Free-Transform PatternsAmong nine resize handle patterns, one spins an object as its rotate handle arcs, one snaps scattered icons into a grid See all demos in this post
If you like this effect - similar demos
Creative UI05 Queue Reorder That Recomputes an Order Value on DragCustom Audio Player CSS — 9 Computed UI Patterns
Creative UI02 Drag to reflow — pull one node and the whole graph rebalancesForce Directed Graph: 9 Network Layout Demos
Creative UI04 Drag-inertia knob — a rotating handle that eases to a stop after releaseCSS Radial Menu: 9 Circular Control Patterns