-
Notifications
You must be signed in to change notification settings - Fork 1
/
colorChanging.js
59 lines (40 loc) · 1.43 KB
/
colorChanging.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
var COLOR = ["Pink","Black","White","Yellow","Orange","Red","Purple","Blue","Brown","Grey","Green"]
var FONT = ["\"Courier New\", Courier, monospace", "\"Comic Sans MS\", cursive, sans-serif", "\"Palatino Linotype\", \"Book Antiqua\", Palatino, serif"]
var currentColor
/*$("*").keydown(function(event){
console.log(INPUT += event.which+".")
if(INPUT == "65.65.71.71.79.79.83.83.84.84.79.79."){*/
/*--------------------------------jQuery-------------------------------------------*/
$(document).ready(function(){
var b = $('<button/>',
{
text: 'Change me',
click: function () {
$( "*" ).css({
"color": genColor(),
"background-color": genColor(),
"font-size": genSize().toString() + "px",
"font-family": genFont(),
})
}
})
$('body').prepend(b)
})
/*--------------------------------jQuery-------------------------------------------*/
function genColor(){ //gera um cor do array de cores
var newColor
//to avoid color repetitiom
do{
newColor = COLOR[Math.floor(Math.random()*COLOR.length)] // .length to add or remove elements from COLOR[]
}while(newColor == currentColor)
currentColor = newColor //atualiza a cor atual
return currentColor
}
function genFont(){ return FONT[Math.floor(Math.random()*FONT.length)]}
function genSize(){
var s
do{
s = Math.floor(Math.random()*100)
}while(s < 4)
return s + "px"
}