Created
March 6, 2013 10:07
-
-
Save darkfe/5098274 to your computer and use it in GitHub Desktop.
十六进制 和rgb 互转
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'#fff'.replace(/^#(\w)(\w)(\w)$/,'#$1$1$2$2$3$3').replace(/#|\w{2}/g,function($a,index){ | |
if($a=='#')return 'rgb(' | |
else return parseInt($a,16) + (index == 5 ? ')' : ','); | |
}) | |
'rgb(255,0,255)'.replace(/[\D]+(\d+)\)?/g,function($a,$1,i){ return (!i?'#':'') + (+$1).toString(16).replace(/^\w$/,'$&$&') }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment