I m looking for a way to sort my elements, but it isn t as easy as it sounds. Please let me explain
My elements are grouped per 6 elements (thumbnails), each x represents a thumbnail However all thumbnails are inside one div
xx xx xx
xx xx xx
xx xx xx
The first column (6 x s) is visible and when you click on a button the next column appears and the old one disappears.
If it happens that the ammount of x s is not possible to devide with 6, e.g. you have 11 x s, then it adds filler elements (o s)
xx xx
xx xx
xx x0
If each element no matter thumbnail or filler represents a number in which order their added in this table then it looks like this
1,2 3,4 5,6
7,8 9,10 11,12
13,14 15,16 17,18
However I want to have the latest thumbnails (1->6) on the initial page. as they are the latest (newest thumbnails) so I want to show them first. (ordered by date ) Which means the previous table needs to be like this:
1,2 7,8 13,14
3,4 9,10 15,16
5,6 11,12 17,18
Now the difficulty is that it should re-order the thumbnails no matter how many columns there are whether there are only 2 columns or 10 columns.
Here s a live link of the problem (2 columns, 7 thumbnails and 5 fillers): link text then click on gallery and you ll see column 1 (6 thumbnails)
all the elements (thumbnails and fillers) are insert into an array (javascript) so I would need to change it s position for each element with JS (or jquery if easier for you)
I know this isn t really a simple question, I tried my best to explain if you have any questions regarding the question feel free to ask and I ll answer asap.
edit: OK I m a lot closer thanks to Vincent Robert. My array of objects (my thumbnails are in here) just now needs to be ordered the way it does with Vincent s array of numbers. I tested out his method which orders the elements of the array to their perfect place. They use the number as index, but I don t have that. Anyone know how to do this?