Skip to content

Commit c0bf2b2

Browse files
authored
add color() function to color tool (mdn#176)
1 parent 4f67fbe commit c0bf2b2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

modules/colors.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
<th>HWB</th>
7878
<td></td>
7979
</tr>
80+
<tr id="colorfunc">
81+
<th>color()</th>
82+
<td></td>
83+
</tr>
8084
</tbody>
8185
</table>
8286

@@ -144,6 +148,19 @@
144148
cell.textContent = `rgb(${R} ${G} ${B} / ${opacity})`;
145149
}
146150
createHSL(R, G, B, opacity);
151+
createColorFunc(R, G, B, opacity);
152+
}
153+
154+
function createColorFunc(r, g, b, opacity) {
155+
const cell = document.querySelector("#colorfunc td");
156+
const R = Number((r / 255).toFixed(2));
157+
const G = Number((g / 255).toFixed(2));
158+
const B = Number((b / 255).toFixed(2));
159+
if (opacity === 1) {
160+
cell.textContent = `color(srgb ${R} ${G} ${B})`;
161+
} else {
162+
cell.textContent = `color(srgb ${R} ${G} ${B} / ${opacity})`;
163+
}
147164
}
148165

149166
function createHSL(r, g, b, opacity) {

0 commit comments

Comments
 (0)