Here is a sample code for a spiral pattern:
case 'spiral': $('.block', grid).css({ 'opacity': 0 }); var order = new Array(); var rows2 = rows/2, x, y, z, n=0; for (z = 0; z < rows2; z++){ y = z; for (x = z; x < cols - z - 1; x++) { order[n++] = y * cols + x; } x = cols - z - 1; for (y = z; y < rows - z - 1; y++) { order[n++] = y * cols + x; } y = rows - z - 1; for (x = cols - z - 1; x > z; x--) { order[n++] = y * cols + x; } x = z; for (y = rows - z - 1; y > z; y--) { order[n++] = y * cols + x; } } for (var m = 0; m < n; m++) { $('.block-' + order[m], grid).stop().delay(100*m).animate({ opacity: 1 }, { duration: 420, complete: (m != n - 1) || function () { alert('done'); } }); } break;
See how this script works.
I also enhanced your "RANDOM" animation to show all the squares, not just a subset. Code for this:
case 'random': var order = new Array(); var numbers = new Array(); var x, y, n=0, m=0, ncells = rows*cols; for (y = 0; y < rows; y++){ for (x = 0; x < cols; x++){ numbers[n] = n++; } } while(m < ncells){ n = Math.floor(Math.random()*ncells); if (numbers[n] != -1){ order[m++] = n; numbers[n] = -1; } } $('.block', grid).css({ 'opacity': 0 }); for (var m = 0; m < ncells; m++) { $('.block-' + order[m], grid).stop().delay(100*m).animate({ opacity: 1 }, { duration: 420, complete: (m != ncells - 1) || function () { alert('done'); } }); } break;
See how this script works.
Neil source share