jQuery滑块颜色选择器/滑块来改变背景

时间:2012-01-27 16:56:37

标签: jquery slider color-picker

我正在尝试:

降低滑块的温度值,我需要代表星形的圆圈逐渐增加并更改背景颜色作为此链接:http://astro.unl.edu/naap/hr/animations/hrExplorer.html

但我的代码没有这样做.....请参阅$(“#s_tem”)中的行.strip({ 请参阅我的代码:http://jsfiddle.net/NxNXJ/19/

谢谢..

1 个答案:

答案 0 :(得分:1)

您正在分配变量selectedColor值,如:#597459745974

哪些不是有效的CSS颜色属性。

[编辑]这里有一些代码可以帮助您:

$("#s_tem").slider({
    change: function(event, ui)
    {       
        var hexValue = ui.value.toString(16).toUpperCase();
        if (hexValue.length < 2) hexValue = "0" + hexValue;

        var chosenColor = NumberToHexColor(hexValue);

        $('#t_tem').val(chosenColor);
        $("#star").css('background-color', chosenColor);

    },
    value: 5800,
    min: 2300,
    max: 40000,
    step: 100,  
});

function NumberToHexColor(Number)
{
    var HexColor = '' + Number;
    while (HexColor.length < 6) 
    {
        HexColor = '0' + HexColor;
    }

    return '#'+ HexColor;
}
相关问题