JavaScript: Automatically order a variable multi-dimensional array diagonally

This is more like a math related question.

I'm trying to create a cute fading effect with jQuery, by splitting a element in a certain number of blocks, then fading each of them, but delay the fading effect based on another array.

So to create the blocks table I have two variables:

var rows = 4,
    cols = 10;

This will divide the element into blocks like:

              0   1   2   3   4   5   6   7   8   9
             10  11  12  13  14  15  16  17  18  19
             20  21  22  23  24  25  26  27  28  29
             30  31  32  33  34  35  36  37  38  39

Then I'm creating another array which decides how the blocks will animate. For example, for a left-to-right diagonal animation this array would look like:

order = [0, 10, 1, 20, 11, 2, 30, 21, 12, 3, 31, 22, 13, 4, 32, 23, 14, 5, 33, 24, 15, 6, 34, 25, 16, 7, 35, 26, 17, 8, 36, 27, 18, 9, 37, 28, 19, 38, 29, 39];

and for this specific case it works :D

My question is how could I create the order array automatically, not manually, based on the number of blocks (rows x columns), which can change ?

Thank you

7
задан Alexandra 29 April 2011 в 14:42
поделиться