I create a single player game. So far I have worked on most things, but flip-card animation is a pain in **.
See this script (it can be a little slower, as the whole game code is in it)
When you drag the card, the back of the card is replaced by the front. This is done in this part of the code:
upturn: function () {
with(this) {
if (is_downturned()) {
element.children('.downturned')
.removeClass('downturned').addClass(_SUITS[_suit()].color)
.append('<img height="80px" width="50px" border="0" src="http://mauricederegt.com/test/solitaire/cards/' + _RANKS[_rank()] + '' + _SUITS[_suit()].symbol + '.jpg">')
element.addClass(_scope());
if (element.hasClass('ui-draggable-disabled')) {
element.draggable('enable');
} else {
element.draggable({
containment: '#field',
revert: 'invalid',
revertDuration: 200,
zIndex: 99
});
}
if (!element.hasClass('ui-droppable-disabled')) {
element.droppable($.extend(DROPPABLE_OPTIONS, {
accept: _tableau_pile_scope()
}));
}
}
}
}
It basically removes the back of the map ( .removeClass('downturned')) and adds a new class ( .addClass(_SUITS[_suit()].color)), where suitsis hart, clover, etc., and coloris black or red.
Now that this action happens, I want to add a nice flip animation.
I played with some textbooks on the Internet, but did not give me a working solution (basically, the cards started acting strange or the game stopped working).
Closest I could add:
-webkit-perspective: 600px;
-webkit-transform-style: preserve-3d;
-webkit-transform: rotateY(180deg);
/* -- transition is the magic sauce for animation -- */
-webkit-transition: 0.6s;
CSS :
.red,
.black {
cursor: pointer;
<<<code added here>>>
}
, , ( ):
, ? , - .
EDIT:
this.element.addClass('container').append('<div class="downturned">'); this.element.addClass('container').append('<div class="downturned">').append('<div class="hiddencardfront">'); JS, div (, , -),