js 翻转颜色实现代码


function reverseColor(rgbColor) {//205,15,20
// console.log(rgbColor);
rgbColor = rgbColor.replace(/\s/g, "");
var arrRGB = new Array(3);
if (rgbColor.indexOf("rgb") > -1) {
var colorReg = /\s*\d+,\s*\d+,\s*\d+/i;
var t = colorReg.exec(rgbColor)[0].split(",");
console.log(t);
for (var i = 0; i < arrRGB.length; i++) {
arrRGB[i] = 255 - t[i];
}
}
else if (rgbColor.indexOf("#") > -1) {
if (rgbColor.length > 4)//"#fc0,#ffcc00"
{
var j = 1;
for (var i = 0; i < arrRGB.length; i++) {
arrRGB[i] = 255 - parseInt(rgbColor.substr((i + j), 2), 16);
j += 1;
}
} else {
for (var i = 0; i < arrRGB.length; i++) {
var t = rgbColor.substr((i + 1), 1);
t = t + t;
arrRGB[i] = 255 - parseInt(t, 16);
}
}
}
return "rgb(" + arrRGB.join(",") + ")";
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdsjff.html