A jQuery plugin provides color sampler function for Canvas.
Compress JS
Compress CSS
Uncompress JS
Uncompress CSS
You can also install color-sampler by using Bower.
bower install color-sampler
You could just use jQuery bind
, delegate
or on
to listen event.
HTML
<canvas id="#canvas">
</canvas>
JavaScript
$('#canvas').colorSampler({
onPreview: function (color) {
// ... or sampler:preview event
},
onSelect: function (color) {
// ... or sampler:select event
}
});
Preview event.
Select event.
Enable the color sampler function.
Disable the color sampler function.
When timer is disabled, call this method to tell color sampler that canvas size change.
Set interval of timer that check canvas resize.
Interval of timer. Set 0 to disable timer, and you can use resize()
to update manually.
$('#canvas').colorSampler('enable');
$('#canvas').colorSampler('disable');
$('#canvas').colorSampler('resize');
$('#canvas').bind('sampler:preview', function (e, color) {
// ...
});
$('#canvas').bind('sampler:select', function (e, color) {
// ...
});
// disable timer
$.colorSampler.setInterval(0);
The project is released under the MIT license.
The project's website is located at https://github.com/emn178/color-sampler
Author: Chen, Yi-Cyuan (emn178@gmail.com)