我正在使用jquery colors要将颜色从十六进制转换为 hsl,请通过添加 0 到 360 之间的数字来修改其色调,然后执行 mod 360 以获得我实际上有兴趣获得的新色调值
问题是我不知道如何将其正确转换回 RGB
给定以下示例(您可以在 jsfiddle here 上测试它),为什么 hslAfter
会这样?具有与 hsl
不同的值?
据我所知,我只是在转变originalColor
它是十六进制的,到 HSL 值数组,然后尝试从中创建一个字符串,在 hslAfter
中.
function testHue() {
var originalColor = $.colors($("#originalColor").val());
var hsl = $.colors(originalColor).model('HSL').get();
var hslAfter = $.colors(hsl).toString('hsl');
var hex = $.colors(hsl).toString('hex');
}
不应该hslAfter
具有与 hsl
相同的值? (我什至没有在这里提到新的十六进制值,当然,它应该与原始的十六进制颜色相同)
我在这里遗漏了一些东西吗(无论如何要解决这个问题)?
最佳答案
您刚刚错过了一些参数 as per the documentation ...
$.colors( colorInput, [formatName], [modelName] )
Creates a color based on the arguments. Returns the color object.
colorInput A string or array representing a color
formatName The name of the format of the color
modelName The name of the color model of the color
这是一个演示,其中十六进制输出现在与十六进制输入相同...
关于jquery 颜色,RGB 到 HSL 并返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7561134/