-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (48 loc) · 1.61 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
48
49
50
51
52
53
54
55
56
57
58
// Code By Webdevtrick ( https://webdevtrick.com )
var body = document.body,
rhexVal_out = document.querySelector('#final-hexVal-r');
ghexVal_out = document.querySelector('#final-hexVal-g');
bhexVal_out = document.querySelector('#final-hexVal-b');
reverse_value = document.querySelector('.reverse-value');
body.style.color = "#ffffff";
function setColor(){
var r_hexVal = pad(parseInt(r.value, 10).toString(16)),
g_hexVal = pad(parseInt(g.value, 10).toString(16)),
b_hexVal = pad(parseInt(b.value, 10).toString(16))
// reverse values
reverse_r = pad(parseInt(255 - r.value, 10).toString(16)),
reverse_g = pad(parseInt(255 - g.value, 10).toString(16)),
reverse_b = pad(parseInt(255 - b.value, 10).toString(16)),
body.style.backgroundColor = "#" + r_hexVal + g_hexVal + b_hexVal;
reverse_value.style.color = "#" + reverse_r + reverse_g + reverse_b;
rhexVal_out.value = r_hexVal;
ghexVal_out.value = g_hexVal;
bhexVal_out.value = b_hexVal;
}
function pad(n){
return (n.length<2) ? "0"+n : n;
}
r.addEventListener('change', function() {
setColor();
outputR.value = r.value;
}, false);
r.addEventListener('input', function() {
setColor();
outputR.value = r.value;
}, false);
g.addEventListener('change', function() {
setColor();
outputG.value = g.value;
}, false);
g.addEventListener('input', function() {
setColor();
outputG.value = g.value;
}, false);
b.addEventListener('change', function() {
setColor();
b_out.value = b.value;
}, false);
b.addEventListener('input', function() {
setColor();
b_out.value = b.value;
}, false);