Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function InvertColor(color,short) {
- if(typeof color === 'undefined') return false;
- if(typeof short === 'undefined') var short = false;
- color = color.substr(1);
- if (color.length === 3) {
- var color = color[0]+color[0]+color[1]+color[1]+color[2]+color[2];
- }
- var colornum = {1:255-parseInt(color[0]+color[1], 16), 2:255-parseInt(color[2]+color[3], 16), 3:255-parseInt(color[4]+color[5], 16)};
- var hex = (String("00" + colornum[1].toString(16)).slice(-2)+String("00" + colornum[2].toString(16)).slice(-2)+String("00" + colornum[3].toString(16)).slice(-2)).toUpperCase();
- if(short === true && hex[0] === hex[1] && hex[2] === hex[3] && hex[4] === hex[5]){
- return '#'+hex[0]+hex[2]+hex[4];
- } else {
- return '#'+hex;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment