changing colors with jquery with a color picker?
i ha开发者_开发技巧ve 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 :))
Just as further reference... HTML5 already include "color" as an Input type.
<label for="bg">Choose color:</label>
<input id="bg" type="color" />
Plus, you can apply some css style with:
input[type="color"]{/*css-here*/}
Now, for the main question... you can capture the color value to change the bg-color with a simple script. Live example: http://jsfiddle.net/7jg4e/152/
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);
}
});
How about:
$('#colorSelector').ColorPicker({
onChange: function(hsb, hex, rgb)
{
$("#full").css("background-color", hex);
}
});
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);
}
});
I have the same problem and below is my solution.
edit colorpicker.js line 96
from
cal.data('colorpicker').onChange.apply(cal, [col, HSBToHex(col), HSBToRGB(col)]);
to
cal.data('colorpicker').onChange.apply(cal, [col, HSBToHex(col), HSBToRGB(col), cal.data('colorpicker').el]);
on change event instead of onChange: function (hsb, hex, rgb) ...
to
onChange: function (hsb, hex, rgb,el) {
$(el).val('#' + hex);
}
let drawingBuffer getColor(colorPicker) { let color = 'ColorPicker1'; this.drawingBuffer = document.getElementsByClassName("colorSets"); for (var i = 0; i < this.drawingBuffer.length; i++) { this.drawingBuffer[i].style.color = colorPicker; } this.drawingBuffer.style.color = colorPicker; return color; }
<div class="colorSets">test</div> <div class="colorSets">test1</div> <input name="MyColorPicker" id="ColorPicker1" [cpPresetLabel]="color" [(colorPicker)]="color" [style.background]="color" (colorPickerChange)="getColor($event)"/> //this is not working in snipest but use as it code and then use npm install it will work for you
精彩评论