-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (34 loc) · 1.15 KB
/
index.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
let color1 = document.querySelector('.color1');
let color2 = document.getElementById('color2');
let body = document.getElementById('gradient');
let css = document.getElementById('h3');
let randomColor = document.getElementById('random');
let autoColor = document.getElementById('auto');
let stopAuto = document.getElementById('stop')
function setGradient() {
body.style.background = `linear-gradient(to left, ${color1.value}, ${color2.value})`;
css.textContent = `linear-gradient(to left, ${color1.value}, ${color2.value})`;
};
function random() {
const randomColor = `#`+ (Math.random() * 0xFFFFFF << 0).toString(16);
return randomColor
};
function randomGradient() {
color1.value = random();
color2.value = random();
setGradient();
};
let interval;
function auto() {
interval = setInterval(randomGradient, 2000);
}
function stop() {
clearInterval(interval);
interval = null;
};
setGradient();
color1.addEventListener('input', setGradient);
color2.addEventListener('input', setGradient);
randomColor.addEventListener('click', randomGradient);
autoColor.addEventListener('click', auto);
stopAuto.addEventListener('click', stop)