Skip to content

Instantly share code, notes, and snippets.

@sagnew
Last active August 29, 2015 14:16
Show Gist options
  • Save sagnew/a92a5a22ed3a93d86690 to your computer and use it in GitHub Desktop.
Save sagnew/a92a5a22ed3a93d86690 to your computer and use it in GitHub Desktop.
$(document).ready(function(){
var total = $("div[id^='0']").length;
var count = 0;
var click_array = [];
var run = function(){
$('td>div').each(function() {
$(this).one( "click", function() {
$( this ).css( "background-color", "blue" );
click_array.push(this);
++count;
if (count === total){
$('#indicator').css( "background-color", "red" );
click_array = click_array.reverse();
var changeColor = function(index) {
var div = click_array[index];
$(div).css( "background-color", "white" );
if(index < click_array.length){
if(index+1 === total){
$('#indicator').css( "background-color", "green" );
click_array = []
count = 0;
run();
}
setTimeout(function(){
changeColor(index + 1);
}, 1000)
}
};
setTimeout(function() {
changeColor(0);
}, 1000);
}
});
});
};
run();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment