| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Soon to be RICHdoggie! Join Date: Jan 2005 Location: UK
Posts: 2,408
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | HEX colors - get same color a bit paler? Hi. Is there any way to take a hex code color, and then get the same color a bit paler? IE: If I had #000000, it may output #c0c0c0 Is there any way of doing that? Thanks Tom |
| |
| | #2 (permalink) |
| Buy my domains. Join Date: Feb 2006
Posts: 2,796
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | You can do it with RGB colors. Code: <script type="text/javascript">
function cutHex(h) { return (h.charAt(0)=="#") ? h.substring(1,7) : h}
function toR(h) {return parseInt((cutHex(h)).substring(0,2),16)}
function toG(h) {return parseInt((cutHex(h)).substring(2,4),16)}
function toB(h) {return parseInt((cutHex(h)).substring(4,6),16)}
function hex(h) {document.getElementById('rgb').value = 'rgb('+toR(h)+','+toG(h)+','+toB(h)+')'}
</script>
<input type="text" onkeyup="hex(this.value);"> <input type="text" id="rgb"> ????: NamePros.com http://www.namepros.com/programming/232819-hex-colors-get-same-color-bit.html Then when you have the RGB, you can just add the same number to each one to make it lighter. |
| |