I'm creating a game, where there are three cups that need to shuffle. I created the HTML and CSS for the game but I'm stuck at moving the three cups with Javascript.
The problem is that two cups need to switch with each other, and having the shuffle effect also.(that you see the cups moving effect) I already found some information about shuffling the divs, but then you don't see the shuffeling effect.. I hope that someone can help me.
This is the code I tried, which worked but ofcource doesn't have the effect what I need.
$(document).ready(function(){
$("#start").bind('click', shuffle);
function shuffle(){
$(".cupBox").each(function(){
var divs = $(this).find('div');
for(var i = 0; i < divs.length; i++) $(divs[i]).remove();
//the fisher yates algorithm, from http://stackoverflow.com/questions/2450954/how-to-randomize-a-javascript-array
var i = divs.length;
if ( i == 0 ) return false;
while ( --i ) {
var j = Math.floor( Math.random() * ( i + 1 ) );
var tempi = divs[i];
var tempj = divs[j];
divs[i] = tempj;
divs[j] = tempi;
}
for(var i = 0; i < divs.length; i++) $(divs[i]).appendTo(this);
});
}
});
Link to JsFiddle
Thanks in advance!