javascript16进制颜色转换为RGB
[javascript]
function toRGB(hexColor) {
return {
r: parseInt(hexColor.slice(1, 3), 16),
g: parseInt(hexColor.slice(3, 5), 16),
b: parseInt(hexColor.slice(5, 7), 16)
};
}
function toRGB1(hexColor) {
var matches = hexColor.match(/\w\w/g);
return {
r: parseInt(matches[0], 16),
g: parseInt(matches[1], 16),
b: parseInt(matches[2], 16)
};
}
function toRGB2(hexColor) {
var hex = parseInt(hexColor.slice(1), 16);
return {
r: hex >> 16,
g: hex >> 8 & 0xff,
b: hex & 0xff
};
}
console.info(toRGB('#76400E'));
console.info(toRGB1('#76400E'));
console.info(toRGB2('#76400E'));
[/javascript]