showing results for - "javascript add alpha to hex"
Michele
09 Feb 2018
1function addAlpha(color: string, opacity: number): string {
2    // coerce values so ti is between 0 and 1.
3    const _opacity = Math.round(Math.min(Math.max(opacity || 1, 0), 1) * 255);
4    return color + _opacity.toString(16).toUpperCase();
5}
6addAlpha('FF0000', 1); // returns 'FF0000FF'
7addAlpha('FF0000', 0.5); // returns 'FF000080'
8
Vanessa
01 Jul 2018
110000000