const useHexToRgba = (hexColor: string, alpha: number): string => {
hexColor = hexColor.replace("#", "");
const r = parseInt(hexColor.substring(0, 2), 16);
const g = parseInt(hexColor.substring(2, 4), 16);
const b = parseInt(hexColor.substring(4, 6), 16);
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
};
useHexToRgba('#DHFKCS',0.2); // 'rgba(13, 15, 12, 0.2)'
使用Ts封装一个函数,传递一个16进制颜色值和一个透明度,转换成rgba的形式
于 2024-09-10 14:58:45 首次发布