判断两种颜色值是否为相似颜色
//Title : 判断两种颜色值是否为相似颜色
//Author : CnLei
//WebSite : http://www.cnlei.com
//真正应用时,请将alert()提示信息注释掉或删除掉
function isSimilarColor(sHexColorA,sHexColorB,nOffset){
this.offsetNum=Math.abs(nOffset);
this.offsetNum>255?this.offsetNum=this.offsetNum-256:"";
var arrNumA=[parseInt(sHexColorA.substring(0,2),16),
parseInt(sHexColorA.substring(2,4),16),
parseInt(sHexColorA.substring(4,6),16)];
var arrNumB=[parseInt(sHexColorB.substring(0,2),16),
parseInt(sHexColorB.substring(2,4),16),
parseInt(sHexColorB.substring(4,6),16)];
for (var i=0;ithis.offsetNum){
alert("不相似\n第"+i+"组的差值为:"+(arrNumA[i]-arrNumB[i])+",\n超过了最大误差:"+this.offsetNum);
return false;
};
}
alert("相似色\n"+sHexColorA+"\n"+sHexColorB)
return true;
}
isSimilarColor("FFFFFF","F0FFFE",10);
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]