Home > Web Front-end > JS Tutorial > body text

js flip color implementation code_javascript skills

WBOY
Release: 2016-05-16 18:32:08
Original
1436 people have browsed it
复制代码 代码如下:

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(",") ")";
}

演示代码:
Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template