-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrid.js
More file actions
55 lines (36 loc) · 1.04 KB
/
grid.js
File metadata and controls
55 lines (36 loc) · 1.04 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
$(document).ready(function() {
populate(16);
$('#reset').on('click', function () {
reset();
})
$('#random_color').on('click', function () {
randomize();
})
});
function populate(size) { // populate grid with a proper amount of squares
var s_size = (960 / size);
if($('.square')[0]) {
$('.square').remove(); // empty the grid if there are squares already
}
for(var i = 0; i < (size*size); i++) {
$('.wrapper').append("<div class='square'> </div>");
}
$('.square').width(s_size);
$('.square').height(s_size);
sketch();
}
function sketch() {
$('.square').hover(function(){
$(this).css('background-color', 'black'); // change div color to black on hover
});
}
function reset() {
var new_size = prompt('Enter a new amount of squares in a row');
populate(new_size);
}
function randomize() {
$('.square').hover(function() {
var randomColorChange = '#'+(Math.random()*0xFFFFFF<<0).toString(16); // generate random div colors on hover
$(this).css('background-color', randomColorChange);
});
}