1、16进制转rgba
16进制颜色模版
转换代码
function hexToRgba(hex){
const rgba = [];
hex = hex.replace('#', '').padEnd(8, 'F');
for (let i = 0; i < hex.length; i+=2) {
rgba.push(parseInt(hex.slice(i, i+2), 16))
}
return rgba;
}
文章来源:https://uudwc.com/A/0k1ZZ
2、rgba转16进制
function rgbaToHex(rgba){
let hex = '#';
for (const i of rgba) {
hex += i.toString(16).padStart(2, '0');
}
return hex;
}
文章来源地址https://uudwc.com/A/0k1ZZ