Created
May 23, 2019 20:38
-
-
Save adalbertopita/66965167741c6523465c2c7fba09379d to your computer and use it in GitHub Desktop.
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
function hexify(color) { | |
var values = color | |
.replace(/rgba?\(/, '') | |
.replace(/\)/, '') | |
.replace(/[\s+]/g, '') | |
.split(','); | |
var a = parseFloat(values[3] || 1), | |
r = Math.floor(a * parseInt(values[0]) + (1 - a) * 255), | |
g = Math.floor(a * parseInt(values[1]) + (1 - a) * 255), | |
b = Math.floor(a * parseInt(values[2]) + (1 - a) * 255); | |
return "#" + | |
("0" + r.toString(16)).slice(-2) + | |
("0" + g.toString(16)).slice(-2) + | |
("0" + b.toString(16)).slice(-2); | |
} | |
var myHex = hexify('rgba(0,0,0, 0.53)'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment