Skip to content

Instantly share code, notes, and snippets.

@lanqy

lanqy/hex2rgb.js

Created Feb 16, 2013
Embed
What would you like to do?
Hex to RGB or RGBA transluder
// from http://snipplr.com/view/43542/
function hex2rgb(hex, opacity) {
var rgb = hex.replace('#', '').match(/(.{2})/g);
var i = 3;
while (i--) {
rgb[i] = parseInt(rgb[i], 16);
}
if (typeof opacity == 'undefined') {
return 'rgb(' + rgb.join(', ') + ')';
}
return 'rgba(' + rgb.join(', ') + ', ' + opacity + ')';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.