DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> js 翻轉顏色實現代碼
js 翻轉顏色實現代碼
編輯:關於JavaScript     
復制代碼 代碼如下:
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(",") + ")";
}

演示代碼:

[Ctrl+A 全選 注:如需引入外部Js需刷新才能執行]
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved