Skip to content

Instantly share code, notes, and snippets.

@ajskelton
Last active December 31, 2016 14:42
Show Gist options
  • Save ajskelton/9991206 to your computer and use it in GitHub Desktop.
Save ajskelton/9991206 to your computer and use it in GitHub Desktop.
A function that takes a HEX code and returns the rgb value.
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