首页 >web前端 >js教程 >js 翻转颜色实现代码_javascript技巧

js 翻转颜色实现代码_javascript技巧

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原创
2016-05-16 18:32:081502浏览
复制代码 代码如下:

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[i] = 255 - t[i];
}
}
else if (rgbColor.indexOf("#") > -1) {
if (rgbColor.length > 4)//"#fc0,#ffcc00"
{
var j = 1;
for (var i = 0; i arrRGB[i] = 255 - parseInt(rgbColor.substr((i + j), 2), 16);
j += 1;
}
} else {
for (var i = 0; i var t = rgbColor.substr((i + 1), 1);
t = t + t;
arrRGB[i] = 255 - parseInt(t, 16);
}
}
}
return "rgb(" + arrRGB.join(",") + ")";
}

演示代码:
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn