📌  相关文章
📜  javascript 将 alpha 添加到十六进制 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:08.177000             🧑  作者: Mango

代码示例1
function addAlpha(color: string, opacity: number): string {
    // coerce values so ti is between 0 and 1.
    const _opacity = Math.round(Math.min(Math.max(opacity || 1, 0), 1) * 255);
    return color + _opacity.toString(16).toUpperCase();
}
addAlpha('FF0000', 1); // returns 'FF0000FF'
addAlpha('FF0000', 0.5); // returns 'FF000080'