Skip to content

Instantly share code, notes, and snippets.

@zalesky
Created September 11, 2017 12:48
Show Gist options
  • Save zalesky/ea968850716feb0dfad6231e1082a7e3 to your computer and use it in GitHub Desktop.
Save zalesky/ea968850716feb0dfad6231e1082a7e3 to your computer and use it in GitHub Desktop.
hex to rgba
let hexToRGB = (hex, opacity) => {
var r = parseInt(hex.slice(1, 3), 16),
g = parseInt(hex.slice(3, 5), 16),
b = parseInt(hex.slice(5, 7), 16);
return opacity ? 'rgba(' + [r, g, b, opacity].join(',') + ')' : 'rgb(' + [r, g, b].join(',') + ')';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment