Created
January 31, 2020 14:51
-
-
Save uptheirons78/f5f4a900b76bacf1749dae007346b6d3 to your computer and use it in GitHub Desktop.
Hex to Rgba Colors Converter Function
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
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