【问题标题】:How can we maker color darker than given color in jquery [duplicate]我们如何使颜色比jquery中的给定颜色更暗[重复]
【发布时间】:2013-05-28 08:57:01
【问题描述】:

假设我有浅红色,我需要更多的红色形式,请您帮助我如何实现。我有像#00ff00这样的十六进制颜色

谢谢

【问题讨论】:

  • 客户设计的“更红”Pantone (c)。

标签: javascript jquery css


【解决方案1】:

在这种情况下不需要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

用法:

var newColor = ColorLuminance("#00ff00", -0.5); // "#334d66" - 50% darker

查看working JSFiddle

来自here的代码sn-p

【讨论】:

    猜你喜欢
    • 2019-05-09
    • 2016-01-09
    • 2015-09-12
    • 2016-02-12
    • 2018-12-04
    • 1970-01-01
    • 2010-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多