如何使用 jquery.css() 通过 hsla 设置背景颜色?

mon*_*ers 4 javascript css jquery

我似乎无法让 jQuery.css() 接受 hsla() 值。传递颜色值的格式不是可接受的吗?这是我尝试过的:

// the below variable outputs a variable value with the following format
// hsla(131, 10%, 100%, 1.0)
var finalcolor = "hsla(" +colx +", " +coly +"%, " +"100%, " +"1.0)";

$('#target-div').css('background', finalcolor);
Run Code Online (Sandbox Code Playgroud)

mar*_*ero 5

它确实有效,但你的颜色只是白色!

在 firebug / chrome 调试器中检查生成的样式,并检查 HSL 2 RGB 转换器。 http://serennu.com/colour/hsltorgb.php