Last active
December 31, 2016 14:42
-
-
Save ajskelton/9991206 to your computer and use it in GitHub Desktop.
A function that takes a HEX code and returns the rgb value.
This file contains 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
function getRGB(hex) { | |
if(hex[0] === '#') { | |
hex = hex.substring(1,7); | |
} | |
var r = parseInt(hex.substring(0,2),16); | |
var g = parseInt(hex.substring(2,4),16); | |
var b = parseInt(hex.substring(4,6),16); | |
return 'rgb(' + r + ', ' + g + ', ' + b + ')'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment