请参阅www.granjacreativa.com/damepaleta 将图像拖入框后,我们会显示主色和调色板。如何显示显示的每种颜色的十六进制值? 我想在每个颜色框下面显示它们。
谢谢
答案 0 :(得分:0)
尝试使用以下functions
var hexDigits = new Array
("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f");
//Function to convert hex format to a rgb color
function rgb2hex(rgb) {
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}
function hex(x) {
return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];
}
阅读Convert jQuery RGB output to Hex Color
已更新,site source
要swatch background color
hex
,colors
,alert(rgb2hex($('.swatch').css('background-color')));
后,您应该在获取swatch background-color
之后尝试,
{{1}}
让所有{{1}}使用$.each()
答案 1 :(得分:0)
你可以获得背景颜色和显示十六进制,这是一个javascript片段:
$('.swatch').on('click',
function(){
var context = document.createElement('canvas').getContext('2d');
context.strokeStyle = $(this).css('backgroundColor');
alert(context.strokeStyle);
}).css('cursor', 'pointer');
我们将使用画布,因为更容易获得实际的十六进制颜色。