Skip to content

Instantly share code, notes, and snippets.

@uptheirons78
Created January 31, 2020 14:51
Show Gist options
  • Save uptheirons78/f5f4a900b76bacf1749dae007346b6d3 to your computer and use it in GitHub Desktop.
Save uptheirons78/f5f4a900b76bacf1749dae007346b6d3 to your computer and use it in GitHub Desktop.
Hex to Rgba Colors Converter Function
const hexToRGBA = (hex, opacity) => {
// remove # from hex color string
const value = hex.replace("#", '');
// get red, green and blue pairings and convert them to their equivalent hexadecimal number
const red = parseInt(value.substring(0,2), 16);
const green = parseInt(value.substring(2,4), 16);
const blue = parseInt(value.substring(4,6), 16);
// return rgba value adding opacity
return `rgba(${red}, ${green}, ${blue}, ${opacity})`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment