Skip to content

Instantly share code, notes, and snippets.

@apapirovski
Created May 2, 2012 19:55
Show Gist options
  • Save apapirovski/2579782 to your computer and use it in GitHub Desktop.
Save apapirovski/2579782 to your computer and use it in GitHub Desktop.
Hexadecimal colour to RGBA
// Convert hex colour to rgba
// ---------------------------------
// hex: hex colour without leading #
// opacity: integer from 0 to 1
function hex2rgba(hex, opacity) {
var r = parseInt(hex.substring(0, 2), 16),
g = parseInt(hex.substring(2, 4), 16),
b = parseInt(hex.substring(4, 6), 16);
return 'rgba(' + r + ', ' + g + ', ' + b + ', ' + opacity + ')';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment