Created
August 17, 2015 11:46
-
-
Save hsnaydd/f73dadc0563cbbe76270 to your computer and use it in GitHub Desktop.
Calculating Color Contrast
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Resource | |
* https://24ways.org/2010/calculating-color-contrast | |
*/ | |
function getContrastYIQ(hexcolor){ | |
var r = parseInt(hexcolor.substr(0,2),16); | |
var g = parseInt(hexcolor.substr(2,2),16); | |
var b = parseInt(hexcolor.substr(4,2),16); | |
var yiq = ((r*299)+(g*587)+(b*114))/1000; | |
return (yiq >= 128) ? 'black' : 'white'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment