css颜色rgba转16进制
rgbaTo16color(color) {
let val = color
.replace(/rgba?\(/, '')
.replace(/\)/, '')
.replace(/[\s+]/g, '')
.split(',');
let a = parseFloat(val[3] || 1),
r = Math.floor(a * parseInt(val[0]) + (1 - a) * 255),
g = Math.floor(a * parseInt(val[1]) + (1 - a) * 255),
b = Math.floor(a * parseInt(val[2]) + (1 - a) * 255);
return "#" +
("0" + r.toString(16)).slice(-2) +
("0" + g.toString(16)).slice(-2) +
("0" + b.toString(16)).slice(-2);
},
网友评论