Skip to content

Instantly share code, notes, and snippets.

@ngehlenborg
Last active August 29, 2015 13:57
Show Gist options
  • Save ngehlenborg/9884544 to your computer and use it in GitHub Desktop.
Save ngehlenborg/9884544 to your computer and use it in GitHub Desktop.
Hex color string to RGB values to create RGBA color
var hexToRgba = function( hexString, alpha ) {
alpha = alpha || 1;
var hexColor = parseInt( hexString.substring(1), 16 );
return ( 'rgba(' + ( ( hexColor << 8 ) >>> 24 ) + ',' + ( ( hexColor << 16 ) >>> 24 ) + ',' + ( ( hexColor << 24 ) >>> 24 ) + ',' + alpha + ')' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment