Created
May 24, 2019 14:06
-
-
Save RiodeJaneiroo/52c382e5b6d295db77bca8add52c2529 to your computer and use it in GitHub Desktop.
[Color range] #css #color #range #scale
This file contains hidden or 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
<div class="textarea-lineup"><span></span></div> | |
<script> | |
colorScale($('.textarea-lineup'), 10); | |
</script> |
This file contains hidden or 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
function colorScale(element, percc) { | |
var procent = (percc > 100) ? 100 : percc; | |
function perc2color(perc) { | |
var r, g, b = 0; | |
if(perc < 50) { | |
r = 255; | |
g = Math.round(5.1 * perc); | |
} | |
else { | |
g = 255; | |
r = Math.round(510 - 5.10 * perc); | |
} | |
var h = r * 0x10000 + g * 0x100 + b * 0x1; | |
return '#' + ('000000' + h.toString(16)).slice(-6); | |
} | |
//do | |
var elSpan = jQuery(element).find('span'); | |
elSpan.css({ | |
'width': procent + '%', | |
'background-color': perc2color(procent) | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment