I am using jQuery .animate method to animate a stack of cards.
Assuming these are the four cards visually displayed [#card1][#card2][#card3][#card4][#card5]
Their div tags , #card1 , #card2, #card3 , #card4 are stored in an array cardStack()
Now i want to animate each of these on click, one after the other when you click them.
So can i do something like
while(cardStack[0]!="undefined"){
$('#cardStack[0]').click(function() {
$('#cardStack[0]').animate({"left": "+=130px","z-index": "1",queue:false},500);
});
i--;
}
is this possible ?
I’ll annotate the source, so that you could actually learn something:
Save the reference to the array of cards.
The first flipped card will be outside our array.
Next, we create an array (with the same length as the
cardsarray), containing information on which cards are flipped.The
flipfunction animates and changes the class attribute of a card.Now we set the click listener.
.index()(http://api.jquery.com/index/) gives you the position of the card from left to right.Lookup our
flippedarray to see if the card is flipped and check that it’s the last card flipped.Here we flip the card.
Here we unflip it.