-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
49 lines (42 loc) · 1.31 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
var h3 = document.querySelector('h3');
var color1 = document.querySelectorAll('input')[0];
var color2 = document.querySelectorAll('input')[1];
var body = document.querySelectorAll('body')[0];
var buttons = document.querySelectorAll('div')[0];
function setColors(){
body.style.background = 'linear-gradient(to right,'+ color1.value +','+color2.value+')' ;
printCSS();
}
function setgGradient(type){
body.style.background = 'linear-gradient('+type+','+ color1.value +','+color2.value+')' ;
printCSS();
}
function printCSS(){
h3.textContent = body.style.background + ";";
}
function randColorGenerator(){
var randomColor = Math.floor(Math.random()*16777215).toString(16);
return randomColor;
}
function setOrientation(event){
var element = event.target.textContent;
if (element === "Diagonal") {
setgGradient('to bottom right');
}
else if (element === "Horizontal"){
setgGradient('to right');
}
else if (element === "Vertical"){
body.style.background = 'linear-gradient('+ color1.value +','+color2.value+') ';
printCSS();
}
else if (element === 'Random'){
color1.value = "#" + randColorGenerator();
color2.value = "#" + randColorGenerator();
}
}
setColors();
printCSS();
color1.addEventListener('input', setColors);
color2.addEventListener('input', setColors);
buttons.addEventListener('click',setOrientation);