How can you use jquery to fill in with squares? Let's say: 20 * 20 any block in height + width? I know that it is necessary to use cycles, but as I still can not think out, help to solve the issue if faced with such)
- Than background-image did not please? - borodatych
- oneWhat have you tried to do? What exactly did not work out? - Dmitriy Simushev
- Community members are not engaged in writing code for applications, but only help to solve specific problems associated with the existing code. - Risto
|
1 answer
Just indulged, just solving your js task
$(function() { var div = $('.div'); for (var i = 0; i < 20; i++) { (function(i) { setTimeout(function() { div.append('<div></div>'); div.find('div:last').css('backgroundColor', color()); }, 50 * i); })(i) } function color() { var arr = ["#66FF99", "#33FF99", "#00FF99", "#33CC66", "#00CC66"]; var rand = Math.floor(Math.random() * arr.length); return arr[rand]; } }); div.div { width: 100px; } div.div > div { width: 20px; height: 20px; background-color: red; float: left; margin: 1px; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="div"></div> |