-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboxes.js
57 lines (53 loc) · 1.74 KB
/
boxes.js
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
55
56
57
$(document).ready(function () {
for (var i = 0; i < 16; i++) {
for (var j = 0; j < 16; j++) {
$('.grid').append("<div class='box white'></div>");
}
}
$('.box').css({
'width': '58px',
'height': '58px'
});
$('.grid').on('mouseenter', '.box.white', function () {
$(this).addClass('highlight');
});
$('.grid').on('mouseenter', '.box.color', function () {
$(this).css('background-color', getRandomColor);
});
$('#standard').on('click', function () {
$('.box').remove();
var gridSize = prompt("How many rows would you like? (1-100)");
var boxSize = (960 - ((gridSize - 1) * 2 + 2)) / gridSize;
for (var i = 0; i < gridSize; i++) {
for (var j = 0; j < gridSize; j++) {
$('.grid').append("<div class='box white'></div>");
}
}
$('.box').css({
'width': boxSize + 'px',
'height': boxSize + 'px'
});
});
$('#color').on('click', function () {
$('.box').remove();
var gridSize = prompt("How many rows would you like? (1-100)");
var boxSize = (960 - ((gridSize - 1) * 2 + 2)) / gridSize;
for (var i = 0; i < gridSize; i++) {
for (var j = 0; j < gridSize; j++) {
$('.grid').append("<div class='box color'></div>");
}
}
$('.box').css({
'width': boxSize + 'px',
'height': boxSize + 'px'
});
});
function getRandomColor() {
var letters = '0123456789ABCDEF'.split('');
var color = '#';
for (var i = 0; i < 6; i++ ) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
});