Skip to content

Instantly share code, notes, and snippets.

@darkfe
Created March 6, 2013 10:07
Show Gist options
  • Save darkfe/5098274 to your computer and use it in GitHub Desktop.
Save darkfe/5098274 to your computer and use it in GitHub Desktop.
十六进制 和rgb 互转
'#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