-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
66 lines (57 loc) · 1.67 KB
/
script.js
File metadata and controls
66 lines (57 loc) · 1.67 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
55
56
57
58
59
60
61
62
63
64
65
66
// declering some constants that will be used later
const css = document.querySelector("h3");
const color1 = document.querySelector(".color1");
const color2 = document.querySelector(".color2");
const body = document.getElementById("gradient");
const linear1 = document.getElementById("linear1");
const linear2 = document.getElementById("linear2");
const linear3 = document.getElementById("linear3");
/* Each of the setGradient functions has the function to change
the background to a gradient. The choice is between linear-gradient,
linear-gradient to right and linear-gradient to bottom right.
*/
function setGradient1() {
body.style.background =
"linear-gradient("
+ color1.value
+ ", "
+ color2.value
+ ")";
css.textContent = "border: " + body.style.background + ";";
};
function setGradient2() {
body.style.background =
"linear-gradient(to right, "
+ color1.value
+ ", "
+ color2.value
+ ")";
css.textContent = "border: " + body.style.background + ";";
};
function setGradient3() {
body.style.background =
"linear-gradient(to bottom right, "
+ color1.value
+ ", "
+ color2.value
+ ")";
css.textContent = "border: " + body.style.background + ";";
};
/* This function will check witch checkbox is checked
and run the coresponding function
*/
function choose() {
if(linear1.checked){
setGradient1();
}else if(linear2.checked){
setGradient2();
}else{
setGradient3();
};
}
// Added event listeners to the elements.
linear2.addEventListener("click", setGradient2);
linear1.addEventListener("click", setGradient1);
linear3.addEventListener("click", setGradient3);
color1.addEventListener("input", choose);
color2.addEventListener("input", choose);