-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
27 lines (22 loc) · 1.01 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
var css = document.querySelector('h3');
var color1 = document.querySelectorAll('input')[0];
var color2 = document.querySelectorAll('input')[1];
var angle = document.querySelector('.angle-input');
var body = document.getElementById('gradient');
function setBackground() {
body.style.background = "linear-gradient(" + angle.value +'deg, ' + color1.value + ", " + color2.value + ")"
css.innerHTML = body.style.background + ';';
}
function setAngle() {
if (angle.value >= 0 && angle.value <= 360) {
if (angle.value === '') {
body.style.background = "linear-gradient(0deg, " + color1.value + ", " + color2.value + ")"
css.innerHTML = body.style.background + ';';
} else {
body.style.background = "linear-gradient(" + angle.value +'deg, ' + color1.value + ", " + color2.value + ")"
css.innerHTML = body.style.background + ';';
}}
}
color1.addEventListener('input', setBackground)
color2.addEventListener('input', setBackground)
angle.addEventListener('input', setAngle)