Jaren

InvertColor

Feb 5th, 2015
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function InvertColor(color,short) {
  2.     if(typeof color === 'undefined') return false;
  3.     if(typeof short === 'undefined') var short = false;
  4.     color = color.substr(1);
  5.     if (color.length === 3) {
  6.         var color = color[0]+color[0]+color[1]+color[1]+color[2]+color[2];
  7.     }
  8.     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)};
  9.     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();
  10.     if(short === true && hex[0] === hex[1] && hex[2] === hex[3] && hex[4] === hex[5]){
  11.         return '#'+hex[0]+hex[2]+hex[4];
  12.     } else {
  13.         return '#'+hex;
  14.     }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment