-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
109 lines (89 loc) · 2.54 KB
/
index.html
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html>
<head>
<style>
.container {
margin: auto;
width: 300px;
text-align: center;
}
.box-container {
margin: auto;
width: 300px;
height: 300px;
position: relative;
}
.color-box {
background-color: green;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
border: 1px solid black;
}
.hint {
z-index: 10;
text-align: center;
margin: auto;
}
.color-selector {
padding: 0 0;
}
.slider {
width: 200px;
}
.row {
width: 100%;
display: flex;
flex-direction: row;
justify-content: center;
text-align: center;
margin: auto;
}
</style>
</head>
<body>
<div class="container">
<h2>Hex color code with transparency</h2>
<div class="box-container">
<div class="hint">Can you see me?</div>
<div id="colorBox" class="color-box"></div>
</div>
<input id="colorSelector" class="color-selector" type="color" onchange="changeColor(this)">
<div class="row">
<p id="hexCode"></p>
</div>
<div class="row">
<input id="opacitySlider" class="slider" type="range">
<p id="opacityLabel">50 %</p>
</div>
</div>
</body>
<script>
var slider = document.getElementById("opacitySlider");
var opacityLabel = document.getElementById("opacityLabel");
var hexValueLabel = document.getElementById("hexCode");
var boxColorInput = document.getElementById("colorSelector");
var colorBox = document.getElementById("colorBox");
boxColorInput.value = "#00FF00";
reloadColor();
slider.oninput = function () {
reloadColor();
}
function hexCodeForColorCode(colorCode) {
var colorPercentage = Math.round(colorCode / 100 * 255);
var hexString = colorPercentage.toString(16);
return hexString;
}
function changeColor(colorInput) {
console.log(colorInput.value);
reloadColor();
}
function reloadColor() {
opacityLabel.innerHTML = slider.value + " %";
hexValueLabel.innerHTML = (boxColorInput.value + hexCodeForColorCode(slider.value)).toUpperCase();
colorBox.style.background = hexValueLabel.innerHTML;
}
</script>
</html>