1717< h2 > Contrast ratio of two colors</ h2 >
1818< p > Pick a foreground and background color</ p >
1919
20- < input type ="color " id ="fg " value ="#B7C9A3 ">
21- < label for ="fg "> Foreground</ label >
22- < input type ="color " id ="bg " value ="#104425 ">
23- < label for ="bg "> Background</ label >
20+ < div class ="picker ">
21+ < input type ="color " id ="fg " value ="#B7C9A3 ">
22+ < label for ="fg "> Foreground</ label >
23+ < p > Luminance: < output id ="fgLuminance "> </ output > </ p >
24+ </ div >
25+ < div class ="picker ">
26+ < input type ="color " id ="bg " value ="#104425 ">
27+ < label for ="bg "> Background</ label >
28+ < p > Luminance: < output id ="bgLuminance "> </ output > </ p >
29+ </ div >
2430
2531< div id ="result ">
2632 < p >
@@ -36,6 +42,8 @@ <h2>Contrast ratio of two colors</h2>
3642
3743var fgInput = document . querySelector ( "#fg" ) ;
3844var bgInput = document . querySelector ( "#bg" ) ;
45+ var fgLuminanceOutput = document . querySelector ( "#fgLuminance" ) ;
46+ var bgLuminanceOutput = document . querySelector ( "#bgLuminance" ) ;
3947var contrastOutput = document . querySelector ( "#contrastResult" ) ;
4048var bgColor , fgColor ;
4149
@@ -44,11 +52,10 @@ <h2>Contrast ratio of two colors</h2>
4452( fgInput . oninput = bgInput . oninput = function ( event ) {
4553 bgColor = hexToArray ( bgInput . value ) ;
4654 fgColor = hexToArray ( fgInput . value ) ;
55+ bgLuminanceOutput . value = sRGB_to_luminance ( bgColor ) ;
56+ fgLuminanceOutput . value = sRGB_to_luminance ( fgColor ) ;
4757 console . log ( "watch" , bgColor , fgColor ) ;
4858 contrastOutput . value = contrast ( bgColor , fgColor ) ;
49- // convert from string to array of number
50- // compute contrast
51- // update span
5259} ) ( ) ;
5360
5461
0 commit comments