Dividing the div into square blocks
i have a div which covers the whole screen now i want to dynamically generate square shaped Divs within this div just like a maths no开发者_如何学JAVAtebook along with giving alternate color to each square blocks
I can't give you too much because I don't know what you've tried and what specific problems you've encountered, but this'd be the basic idea:
for(var i = 0; i < 1000; i++) {
var block = $('<div class="block" />');
block.addClass('block-' + ((i%2)+1));
$('body').append(block);
}
Have your .block
div's float left, and set to the size you want them to be, and they'll automatically wrap to the next row. They'll also have either the class .block-1
or .block-2
, which you can use to set the alternating colors.
Of course, if a background image, as has been suggested in comments, would meet your needs, than that would perform heaps better :)
精彩评论