Created
May 2, 2012 19:55
-
-
Save apapirovski/2579782 to your computer and use it in GitHub Desktop.
Hexadecimal colour to RGBA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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