-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
33 lines (30 loc) · 1.2 KB
/
main.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
getNumber("red");
getNumber("green");
getNumber("blue");
function getNumber(colorString) {
var sliderSelector = colorString + 'Slider';
var codeSelector = colorString + 'Code';
var numberSelector = colorString + 'Number';
var codeSpan = document.getElementById(codeSelector);
var numberInput = document.getElementById(numberSelector);
console.log(colorString);
var sliderNumber = document.getElementById(sliderSelector);
setColor(sliderNumber);
sliderNumber.addEventListener('input', function(e) {
console.log(e.currentTarget.value);
var sliderNumber = e.currentTarget;
setColor(sliderNumber)
});
function setColor(sliderNumber) {
codeSpan.innerText = sliderNumber.value;
numberInput.value = sliderNumber.value;
var colorContent = document.getElementsByClassName("colorContent")[0];
var singleCodes = document.getElementsByClassName("code");
var singleCodeArr = Array.prototype.slice.call(singleCodes);
var rgbArray = [];
singleCodeArr.forEach(function(code) {
rgbArray.push(code.innerText);
})
colorContent.style.backgroundColor = 'rgb(' + rgbArray.toString() + ')';
}
}