Lighter Color
by Digvijay Naruka
HTML
<div class="color-normal">
Normal Color:
</div>
<div class="color1">
color
</div>
CSS
.color-normal{
font-size: 40px;
}
.color1{
font-size: 40px;
}
JavaScript
function ColorLuminance(hex, lum) {
$('.color-normal').css('color',hex);
// validate hex string
hex = String(hex).replace(/[^0-9a-f]/gi, '');
if (hex.length < 6) {
hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2];
}
lum = lum || 0;
// convert to decimal and change luminosity
var rgb = "#", c, i;
for (i = 0; i < 3; i++) {
c = parseInt(hex.substr(i*2,2), 16);
c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);
rgb += ("00"+c).substr(c.length);
}
$('.color1').css('color', rgb);
$('.color1').text(rgb);
return rgb;
}
function getRandomColor() {
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
var cr = getRandomColor;
var newColor= ColorLuminance(cr, -0.1)