Colorpicker plugin for the Twitter Bootstrap toolkit. Originally written by @eyecon
and maintained in Github by @xaguilars and the community
Adds a color picker to a field or any other element.
Attached to a field with hex format specified via options.
Attachet to a field with the rgba format specified via data tag.
As component.
Using events to work with the color.
Destroy them all Create them againCall the colopicker via javascript:
$('.my-colorpicker-control').colorpicker()
Name | type | default | description |
---|---|---|---|
format | string | 'hex' | the color format - hex | rgb | rgba. |
Format a component.
<div class="input-append my-colorpicker-control" data-color="rgb(255, 146, 180)" data-color-format="rgb"> <input type="text" class="span2" value="" > <span class="add-on"><i style="background-color: rgb(255, 146, 180)"></i></span> </div>
Initializes an colorpicker.
Show the color picker
Refreshes the widget colors (this is done automatically)
Hide the color picker
Updates the color picker's position relative to the element
Destroys the colorpicker widget and unbind all .colorpicker events from the element and component
Set a new value for the color picker (also for the input or component value). Triggers 'changeColor' event.
Each triggered events have a color object used internally by the picker. This object has several usefull methods.
Set a new color. The value is parsed and tries to do a quess on the format.
Set the HUE with a value between 0 and 1.
Set the saturation with a value between 0 and 1.
Set the lightness with a value between 0 and 1.
Set the transparency with a value between 0 and 1.
Returns a hash with red, green, blue and alpha.
Returns a string with HEX format for the current color.
Returns a hash with HSLA values.
The colopicker plugin exposes some events (with optional .colorpicker namespace)
Event | Description |
---|---|
create | This event fires immediately when the color picker is created. |
showPicker | This event fires immediately when the color picker is displayed. |
hidePicker | This event is fired immediately when the color picker is hidden. |
changeColor | This event is fired when the color is changed. |
destroy | This event fires immediately when the color picker is destroyed. |
$('.my-colorpicker-control').colorpicker().on('changeColor', function(ev){ bodyStyle.backgroundColor = ev.color.toHex(); });