-
Notifications
You must be signed in to change notification settings - Fork 0
/
backGroundGen.js
25 lines (23 loc) · 1.12 KB
/
backGroundGen.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
var background = document.querySelector("h3");
var color1 = document.querySelector("#color1");
var color2 = document.querySelector("#color2");
var gradient = document.querySelector("#gradient");
var generator = document.querySelector(".generator");
gradient.style.background="linear-gradient(to right, " +color1.value+ ", " +color2.value+ ")";
background.textContent=gradient.style.background+";";
function generate(){
gradient.style.background="linear-gradient(to right, " +color1.value+ ", " +color2.value+ ")";
background.textContent=gradient.style.background+";";
}
color1.addEventListener("input", generate);
color2.addEventListener("input", generate);
//var rand1=Math.random().toString(16).substr(2, 6);
//var rand2=Math.random().toString(16).substr(2, 6);
generator.addEventListener("click", function(){
var rand1=Math.random().toString(16).substr(2, 6);
var rand2=Math.random().toString(16).substr(2, 6);
gradient.style.background="linear-gradient(to right," +" #" +rand1+", " + " #"+rand2+ ")";
background.textContent=gradient.style.background+";";
color1.value="#"+rand1;
color2.value="#"+rand2;
});