In the " every color set within a parent div" section, I assume that child nodes are also needed. It is also necessary to switch the colors of the foreground and background (with the colors of the borders - light mod).
Check out the demo in jsFiddle.
Invert all colors, for example:
var Container = $("#Container");
invertElementColors (Container);
Container.find ('*'). each (function () {
invertElementColors ( $(this) );
} );
Given:
function invertElementColors (jNode) {
jNode.css ( {
'color' : function (J, oldColor) {
return invertRGB_ColorStr (oldColor);
},
'background-color' : function (J, oldColor) {
return invertRGB_ColorStr (oldColor);
}
} );
}
function invertRGB_ColorStr (oldColorStr) {
if (oldColorStr == 'transparent') oldColorStr = 'rgb(255, 255, 255)';
var colorArray = oldColorStr.match (/\((\d+),\s?(\d+),\s?(\d+)\)/);
var newColorStr = $.map (colorArray, function (byte, J) {
if (!J) return null;
return Math.abs (255 - parseInt (byte) );
}
).join (',');
return 'rgb(' + newColorStr + ')';
}
source
share