-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
29 lines (26 loc) · 1.06 KB
/
script.js
File metadata and controls
29 lines (26 loc) · 1.06 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
var css = document.querySelector("h3");
var color1 = document.querySelector(".color1");
var color2 = document.querySelector(".color2");
var body = document.getElementById("gradient");
var randomButton = document.getElementById("random");
changeGradient(); //to display initial gradient
function changeGradient() {
body.style.background = "linear-gradient(to right, "
+ color1.value + ", " + color2.value + ")";
css.textContent = body.style.background+";";
}
//console.log(color1.value);
color1.addEventListener("input",changeGradient);
//console.log(color2.value);
color2.addEventListener("input",changeGradient);
function genRanCol(){ //generate random color
return 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')';
}
function assignRandomColor(){
var hue1 = genRanCol();
var hue2 = genRanCol();
body.style.background = "linear-gradient(to right, "
+ hue1 + ", " + hue2 + ")";
css.textContent = body.style.background+";";
}
randomButton.addEventListener("click",assignRandomColor);