Last active
March 23, 2021 02:34
-
-
Save onebelarusianguy/5f999a0fa8dc4aa01208bab177f4a482 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 to RGB with alpha channel | |
| * @param {Array} [r, g, b] | |
| * @returns {String} rgba string | |
| */ | |
| function hexToRGBA(rgb) { | |
| let lowest = Math.min.apply(null, rgb), | |
| alpha = (255 - lowest) / 255, | |
| value = 'rgba('; | |
| for (let i = 0; i < rgb.length; i++) { | |
| value += parseInt((rgb[i] - lowest) / alpha, 10) + ', '; | |
| } | |
| value += alpha.toFixed(2) + ')'; | |
| return value; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment