//hex -> rgb
export function hexToRgb(hex) {
return 'rgb(' + parseInt('0x' + hex.slice(1, 3)) + ',' + parseInt('0x' + hex.slice(3, 5))
+ ',' + parseInt('0x' + hex.slice(5, 7)) + ')';
}
//hex -> rgba
export function hexToRgba(hex, opacity) {
return 'rgba(' + parseInt('0x' + hex.slice(1, 3)) + ',' + parseInt('0x' + hex.slice(3, 5)) + ','
+ parseInt('0x' + hex.slice(5, 7)) + ',' + opacity + ')';
}
【16进制色值转换】hex(#fff)转rgb或rgba(rgb(0,0,0,0.1))
于 2022-10-13 16:43:25 首次发布