Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing colors with jquery with a color picker?

i have this jquery script that changes the color of the background instantly by entering a color code into the textbox, the working example is in jsfiddle link below.

http://jsfiddle.net/7jg4e/

but instead of the input field i wanted to use a color picker custom skin, becuase i dont want user to deal with hex code(just like twitter). the jquery plugin im trying to use is found at

http://www.eyecon.ro/colorpicker/

at the buttom of the page it has the neat color picker with DOM element.

so the problem is how am i going to change from the input type to the color picker div. thanks :))

like image 450
getaway Avatar asked Nov 10 '10 16:11

getaway


3 Answers

How about:

$('#colorSelector').ColorPicker({
onChange: function(hsb, hex, rgb)
          {
            $("#full").css("background-color", hex);
          }
});
like image 183
Nathan MacInnes Avatar answered Sep 30 '22 06:09

Nathan MacInnes


Replace the input element with a div use something like: (untested!)

HTML

<div id='colourPicker'></div>

JS

$('#colourPicker').ColorPicker({
  onChange: function(hsb, hex, rgb){
    $("#full").css("background-color", '#' + hex);
  }
});

There's an example at the bottom of the link you have which shows you how.

Update for changing text

HTML

<div id='colourPickerText'></div>
<div id='textToBeChanged'>Test text</div>

JS

$('#colourPickerText').ColorPicker({
  onChange: function(hsb, hex, rgb){
    $("#textToBeChanged").css("color", '#' + hex);
  }
});
like image 20
Fermin Avatar answered Sep 30 '22 06:09

Fermin


Thanks keithics..

I had the similar problem. I had to call colorpicker for dynamic buttons. I did with taking class instead of id.

It helped me a lot.

$('.colorSelector').ColorPicker({
onChange: function(hsb, hex, rgb,el)
      {
        $(el).val('#' + hex);
      }
});
like image 33
palak Avatar answered Sep 30 '22 06:09

palak