-
Notifications
You must be signed in to change notification settings - Fork 1
/
animated_script.js
82 lines (63 loc) · 1.61 KB
/
animated_script.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
// Copyright: Princess, CandyRandomizer //
var h3 = document.querySelector("h3");
var color1 = document.querySelector(".color1");
var color2 = document.querySelector(".color2");
var body = document.getElementById("gradient");
var back = document.getElementById("secondBack");
var button = document.getElementById("randomize")
function firstDisplay() {
body.style.background =
"linear-gradient(135deg,"
+ color1.value
+ " 40%,"
+ color2.value
+ ")";
h3.textContent = body.style.background + ";"
}
firstDisplay();
function changeBackground() {
body.style.background =
"linear-gradient(135deg,"
+ color1.value
+ " 40%,"
+ color2.value
+ ")";
back.style.background =
"linear-gradient(135deg,"
+ color2.value
+ " 40%,"
+ color1.value
+ ")";
h3.textContent = body.style.background + ";"
}
color1.addEventListener("input", changeBackground);
color2.addEventListener("input", changeBackground);
// function randomSelector() {
// }
function randomColor() {
var letters = '0123456789ABCDEF';
var randomColor1 = '#';
for (var i = 0; i < 6; i++) {
randomColor1 += letters[Math.floor(Math.random() * 16)];
}
var randomColor2 = '#';
for (var i = 0; i < 6; i++) {
randomColor2 += letters[Math.floor(Math.random() * 16)];
}
color1.value = randomColor1;
color2.value = randomColor2;
body.style.background =
"linear-gradient(135deg,"
+ color1.value
+ " 40%,"
+ color2.value
+ ")";
back.style.background =
"linear-gradient(135deg,"
+ color2.value
+ " 40%,"
+ color1.value
+ ")";
h3.textContent = body.style.background + ";"
}
button.addEventListener("click",randomColor);