Skip to content

Instantly share code, notes, and snippets.

@mmckegg
Created October 17, 2013 06:26
Show Gist options
  • Save mmckegg/7019947 to your computer and use it in GitHub Desktop.
Save mmckegg/7019947 to your computer and use it in GitHub Desktop.
function rgb(hex){
if (hex.charAt(0) == '#'){
var color = hex.slice(1)
var splitter = color.length/3
var value = []
for (var i=0;i<3;i++){
var part = parseInt(color.slice(i*splitter, (i+1)*splitter), 16)
if (splitter == 1){
value[i] = ((part+1)*16)-1
} else {
value[i] = part
}
}
return 'rgb(' + value.join(', ') + ')'
} else {
return hex
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment