Skip to content

Instantly share code, notes, and snippets.

@burakkp
Last active June 20, 2019 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burakkp/25888034ffdf08a184cd90da491e745b to your computer and use it in GitHub Desktop.
Save burakkp/25888034ffdf08a184cd90da491e745b to your computer and use it in GitHub Desktop.
Hex to RGBA convert with javascript
function hexToRGBA(hex){
var c;
if(/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)){
c= hex.substring(1).split('');
if(c.length== 3){
c= [c[0], c[0], c[1], c[1], c[2], c[2]];
}
c= '0x'+c.join('');
return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255].join(',')+',1)';
}
throw new Error('This Hex is not good');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment