javascript/jQuery, :
, ...
Step 1: Remove all divs from dom that have a class with a name fakeSquare. Sort of
$('.fakeSquare').remove();
Step 2: Calculate the number of red divs in one row. Save this number in squaresPreRow. Something like: var squaresPreRow = floor( window width / square width ).
Step 3. After the squaresPreRow + 1red square div add two empty divs. So ...
$("div.redSquare")
.index(squaresPreRow + 1)
.append("<div class="fakeSquare redSquare"></div><div class="fakeSquare redSquare"></div>");
Step 4: add two more squares for the third row ...
$("div.redSquare")
.index((squaresPreRow * 2) + 1)
.append("<div class="fakeSquare redSquare"></div><div class="fakeSquare redSquare"></div>");
Step 5: And again ...
$("div.redSquare")
.index((squaresPreRow * 3) + 1)
.append("<div class="fakeSquare redSquare"></div><div class="fakeSquare redSquare"></div>");
Finally, you want to call this function when the DOM is ready and whenever the window has changed.
This may require some tweaking, but hopefully you can get started.
source
share