-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.js
84 lines (65 loc) · 2.17 KB
/
jquery.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
var gridSize=16;
$(document).ready(function(){
$('body').prepend('<div class="frame"></div>');
$('.frame').css('height', '100vh');//set height to viewport height
drawPad(gridSize);
//Gradient Black mode
$('body').prepend('<button type="button" id="gradient">Gradient</button>');
$('#gradient').on('click', function(){
$('.square')
.hover(function(){
$(this).css('background-color', 'black');
});
$('.square').hover(function(){
var currentOpacity = $(this).css("opacity");
console.log(currentOpacity);
if (currentOpacity != 0){
$(this).css('opacity', currentOpacity - .1);
}
});
});
//Random Color mode
$('body').prepend('<button type="button" id="random">Random Colors</button>');
$('#random').on('click', function(){
$('.square').css({})
.hover(function(){
var randColor = '#'+(Math.random()*0xFFFFFF<<0).toString(16);
$(this).css('background-color',randColor)
});
});
//Resize
$('body').prepend('<button type="button" id="resize">Resize</button>');
$('#resize').on('click', function(){//when resize is clicked,
gridSize = prompt("Please enter the desired grid size: (e.g. 16 will create a 16 x 16 grid)", "16");//prompt for size
$('.row').remove();//remove all rows
drawPad(gridSize);//redraw with new grid
});
});
function drawPad(gridSize){
var winHeight = $('.frame').height();
var winWidth = $('.frame').width()
for(var i = 0; i < gridSize; i++){//create rows
$('.frame').append('<div class="row"></div>');
}
for (var j = 0; j < gridSize; j++){//create colums
$('.row').append('<div class="square"></div>');
}
if (winHeight>winWidth){//check if there is more width space or height space
var square_size = winWidth/gridSize-5;//set size of squares to be proportional to the frame width
}
else{
var square_size = winHeight/gridSize-10;//set size of square to be proportional to the frame width
}
console.log($('.frame').width());
console.log($('.frame').height());
$('.square').css({
display: 'inline-block',
'height': square_size,
'width': square_size,
'border': '1px black solid',
'background-color' :'white'
})
.hover(function(){
$(this).css('background-color','lavender')
});
}