-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
59 lines (41 loc) · 1.24 KB
/
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
var userinput1 = document.querySelector(".userinputcolor1");
var userinput2 = document.querySelector(".userinputcolor2");
var outputofcss = document.querySelector("h3");
var bodybgcolor= document.getElementById("gradient");
var button = document.querySelector("button");
var hidee = document.getElementById("hide");
var divv = document.querySelector("div");
function hidef(){
divv.style.display = 'none';
}
function show(){
divv.style.display = '';
}
function setGradientcolor(){
bodybgcolor.style.background=
"linear-gradient(to right, "
+ userinput1.value
+ ","
+ userinput2.value
+ ")";
outputofcss.textContent = bodybgcolor.style.background + ';' ;
}
function getRandomColor(){
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i <6 ; i++){
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
function randomColors(){
userinput1.value = getRandomColor();
userinput2.value = getRandomColor();
setGradientcolor();
}
setGradientcolor();
userinput1.addEventListener("input", setGradientcolor);
userinput2.addEventListener("input", setGradientcolor);
button.addEventListener("click", randomColors);
hidee.addEventListener("click", hidef);
gradient.addEventListener("keypress", show);