颜色值转化
rgb颜色值转换为hex颜色值(rgb=>hex)
hex颜色值转换为rgb颜色值(hex=>rgb)
代码:
const hex2Rgb = (hex) => {return `rgb(${parseInt(hex.slice(1, 3), 16)},${parseInt(hex.slice(3, 5), 16)},${parseInt(hex.slice(5, 7),16)})`;
};const rgb2Hex = (r, g, b) => {return '#' + byte2Hex(r) + byte2Hex(g) + byte2Hex(b);
};const byte2Hex = n => {var hexString = '0123456789ABCDEF';return String(hexString.substr((n >> 4) & 0x0f, 1)) + hexString.substr(n & 0x0f, 1);
};