我有一个函数可以为我将十六进制代码转换为 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;
}
我不确定是什么决定了基于颜色的等效灰色,我的研究也没有太大帮助。有任何想法吗?