gpt4 book ai didi

javascript - 加深十六进制颜色不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 09:16:07 25 4
gpt4 key购买 nike

我有一个小代码笔,你可以在其中选择你喜欢的颜色来“个性化”网站......它改变了背景颜色和标题颜色(也许以后会更多),但它会将背景更改为与标题,所以标题是不可见的...我有一点 javascript 可以使十六进制颜色变亮/变暗,但这似乎不起作用。 http://codepen.io/tobiasglaus/pen/RKKdqy我试图用 class .title 使每个标题变暗。

代码

$('.title').css('color', color);
$('body').css('background', color);

我更改标题和背景颜色(我的函数称为“颜色”,所以末尾有“,颜色”。使用 $('.title').css.color = lightenDarkenColor(color, -20); 我试图使标题颜色变暗,但那里似乎有一个错误。

最佳答案

我不知道你是否解决了 jet 问题,但你可以在这里查看工作版本:Codepen

这是我添加的方法,而不是你的 lightenDarkenColor()

 //@param  {string} rgb     "rgb(26,26,26)""
//@param {string} type "darken" or "lighten"
//@param {int} percent
//@return {string} returns the altered RGB color

function alterColor(rgb, type, percent) {
rgb = rgb.replace('rgb(', '').replace(')', '').split(',');

var red = $.trim(rgb[0]);
var green = $.trim(rgb[1]);
var blue = $.trim(rgb[2]);

//If rgb is black set it to gray
if (red == 0 && green == 0 && blue == 0) {
red = 100;
green = 100;
blue = 100;
}

if (type === "darken") {
red = parseInt(red * (100 - percent) / 100, 10);
green = parseInt(green * (100 - percent) / 100, 10);
blue = parseInt(blue * (100 - percent) / 100, 10);
} else {
red = parseInt(red * (100 + percent) / 100, 10);
green = parseInt(green * (100 + percent) / 100, 10);
blue = parseInt(blue * (100 + percent) / 100, 10);
}

rgb = 'rgb(' + red + ', ' + green + ', ' + blue + ')';

return rgb;
}

关于javascript - 加深十六进制颜色不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41758977/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com