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

发布于 2024-12-29 18:53:57 字数 362 浏览 5 评论 0原文

我正在尝试这样做:

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

但我的代码没有这样做......查看行来自$("#s_tem").slider({ 查看我的代码: http://jsfiddle.net/NxNXJ/19/

谢谢..

I'm trying to do:

Decreasing the temperature values of the slider, I need that circle that represents the star gradually increase and change background color as this link: http://astro.unl.edu/naap/hr/animations/hrExplorer.html

But my code isn't doing it.....See lines from $("#s_tem").slider({
See my code: http://jsfiddle.net/NxNXJ/19/

Thanks..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二智少女猫性小仙女 2025-01-05 18:53:57

您正在分配变量 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;
}

You are assigning the variable chosenColor values like: #597459745974

Which are not valid CSS color attributes.

[Edit] Here's some code that should get you going:

$("#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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文