Workshop › Klondike Solitaire › Step 31 of 40
On release, a card that did not move is still a tap. A dragged card goes to the pile under the middle of the held card,
not under the pointer: that feels right however you grabbed it. If tryMove refuses, the card simply appears back in its
pile, because it never left it.
```js
const { from, index, moved } = drag
if (!moved) autoMove(from, index)
else {
// Drop on the pile under the middle of the held card.
const target = hit(drag.x - drag.dx + CW / 2, drag.y - drag.dy + CH / 2)
if (target) tryMove(from, index, target.key)
}
```moved is taken out of drag too.autoMove.(x - dx, y - dy); adding half a card gives its middle. hit finds the pile there, and
tryMove tries it.In the pointerup listener, replace the two lines const { from, index } = drag and autoMove(from, index) with the new
lines.
Skills: Keyboard and mouse input, Collision detection
← Draw the held cards at the pointer Drop a king into an empty column →