假设我的颜色浅红色,我需要更多的红色形状,请你帮助我如何实现。我有#00ff00
之类的hexadeciaml颜色谢谢
答案 0 :(得分:11)
在这种情况下不需要jQuery!
function ColorLuminance(hex, lum) {
// 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);
}
return rgb;
}
hex
是十六进制颜色值,lum
是发光度因子,-1&lt; = lum&lt; = 1,负数表示较暗,正面较浅
用法:
var newColor = ColorLuminance("#00ff00", -0.5); // "#334d66" - 50% darker
来自here
的代码段