十六进制 rgb互转
十六进制转rgb
export const = hexToRgb(hex) => {
return 'rgb(' + parseInt('0x' + hex.slice(1, 3)) + ',' + parseInt('0x' + hex.slice(3, 5)) + ',' + parseInt('0x' + hex.slice(5, 7)) + ')'
}
rgb转十六进制
export const RGBToHex = (rgb) => {
let aColor = rgb.split(',')
let strHex = '#';
for(let i = 0; i < aColor.length; i++){
let hex = Number(aColor[i]).toString(16);
if(+hex < 10){
hex = '0' + hex;
}
strHex += hex;
}
if(strHex.length !== 7){
strHex = null;
}
return strHex;
}