简体   繁体   English

jQuery UI颜色选择器问题

[英]jQuery UI color picker issue

I want to create a color picker, but it needs to be horizontal like this http://jqueryui.com/demos/slider/ It needs to be a horizontal slider that can scroll through all colors. 我想创建一个颜色选择器,但是它需要像这样http://jqueryui.com/demos/slider/是水平的。它必须是可以滚动所有颜色的水平滑块。 I am trying to base it off the jquery ui slider. 我试图将其基于jquery ui滑块。

Does anyone know any examples of this from the web? 有人从网上知道任何这样的例子吗? Or could tell me how to do this? 还是可以告诉我该怎么做?

I was thinking based on the distance the slider is set say 50% i would need to convert that value into a color value. 我当时想根据滑块设置的距离说50%,我需要将该值转换为颜色值。

Something like 0% distance is white and 100% is black. 诸如0%距离是白色,而100%是黑色。

Note: it needs to be 1 slider that can range through all colours, and the colors has to be smooth transition not all randomed. 注意:它必须是1个可以在all颜色范围内变化的滑块,并且颜色必须平滑过渡,而不是全部随机。

Like this image: 喜欢这张图片: 在此处输入图片说明 but it somehow needs to incorporate white and black in it. 但它需要以某种方式将白色和黑色结合到其中。

You can represent HTML colors as hex values. 您可以将HTML颜色表示为十六进制值。 With this in mind, we can create a slider that goes from #000000 to #FFFFFF (or 0 to 16777215 in decimal): 考虑到这一点,我们可以创建一个从#000000#FFFFFF (或从0到16777215,以十进制表示)的滑块:

$("#slider").slider({
    min: 0,
    max: 16777215,
    slide: function (event, ui) {
        var hex = "#" + ui.value.toString(16);
        $("#color").css("background-color", hex);
    }
});

Note that for this to be remotely usable, you would have to have a pretty long slider. 请注意,要使其在远程可用,您将需要一个相当长的滑块。 To get a better sense of it working, use the keyboard arrows instead of the mouse to slide through colors. 为了更好地了解其工作原理,请使用键盘箭头而不是鼠标在颜色之间滑动。

Example: http://jsfiddle.net/4extL/46/ 示例: http //jsfiddle.net/4extL/46/

There are a lot of jQuery UI examples here for color pickers. 有很多的jQuery UI的例子在这里的拾色器。 They even have examples where you can scroll through all the colors. 他们甚至提供了示例,您可以在其中滚动浏览所有颜色。 Hope this helps. 希望这可以帮助。

I don't think this is possible. 我认为这是不可能的。 I would recommend using one of the many jQuery colorpicker plugins. 我建议使用许多jQuery colorpicker插件之一。 Or you could look at this jQuery UI example - not exactly what you wanted but it does use the jQueryUI slider: http://jqueryui.com/demos/slider/#colorpicker 或者您可以看一下这个jQuery UI示例-并非您想要的那样,但是它确实使用了jQueryUI滑块: http : //jqueryui.com/demos/slider/#colorpicker

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM