我有一个函数,为我将十六进制代码转换为rgb:
function getRGB(color){
var matchColors = /#(\w{2})(\w{2})(\w{2})/;
var match = matchColors.exec(color);
var r = parseInt(match[1], 16).toString() + ",";
var g = parseInt(match[2], 16).toString() + ",";
var b = parseInt(match[3], 16).toString();
answer = 'rgb(' + r + g + b + ')' ;
return answer;
}
我希望有第二个函数,它也将接受一个十六进制代码,但随后修改它,使其成为与-webit-filter: grayscale(100%)
所做的相同的灰色。
该函数如下所示:
function gray(color){
var matchColors = /#(\w{2})(\w{2})(\w{2})/;
var match = matchColors.exec(color);
var r = parseInt(match[1], 16).toString() + ",";
var g = parseInt(match[2], 16).toString() + ",";
var b = parseInt(match[3], 16).toString();
//code to modify figure out the rgb gray value and assign it to the variable G
answer = 'rgb(' + G + ',' + G + ',' + G + ')' ;
return answer;
}
我不确定是什么决定了基于颜色的等效灰色,我的研究也没有多大帮助。有什么想法吗?
发布于 2013-08-03 19:01:25
https://stackoverflow.com/questions/18039314
复制