|
Post by Schubaltz on Jun 10, 2007 15:35:43 GMT -5
Kind of old, but it works. Description: Darkens/brightens the hex code you provide. Syntax: convertHex(string, condition); var validHex = "0123456789ABCDEF", x = 0; function convertHex(a, b) { var newHex = "", i = 0, x = 0; while(i < a.length) { var returnItem = validHex.charAt(validHex.indexOf(a.charAt(i ++)) + b); newHex += returnItem ? returnItem : 0 + b < 0 ? 0 : "F"; } return newHex; } Example: convertHex("0099CC", x + 2);The first parameter of the function takes the hexcode as a string. The second part uses the variable x to represent the color code as it's value is subtracted or added by any number. In this case we are increasing it's brightness by "2". The result will be: 22BBEE
|
|