I am trying to write a Solitaire card game in Javascript. For dragging and dropping the cards I use jQueryUI. As shown in http://jsfiddle.net/HY8g7/1/ you can drag cards to the column where you stack the cards in a Solitaire game.
Here comes the problem. Say I have all three cards stacked in one column: card 1, card 2 and card 3 each on top of each other. When I drag card 1, card 2 and 3 also need to follow card 1 when dragging around etc.
In order to achieve this I have already tried to make each successor card a child of the previous card. Unfortunately this method causes lots of DOM manipulation and dragging does not work as expected.
When I move a card to an invalid droppable it should be moved back to its original position which I now achieve with:
$('.card').draggable({
revert: 'invalid'
});
This should still work when I move a stack of cards around.
Does anyone have an idea what could be a clean approach to drag the pile of cards around, when picked at an arbitrary point?