PitPik / colorPicker

Advanced javaScript color picker and color conversion / calculation (rgb, hsv, hsl, hex, cmyk, cmy, XYZ, Lab, alpha, WCAG 2.0, ...)
http://www.dematte.at/colorPicker/
MIT License
570 stars 136 forks source link

jqColor repeat call renderCallback #37

Closed huyinghuan closed 8 years ago

huyinghuan commented 8 years ago

i console.log in renderCallBack it will repeate output when click one time in color picker area.

for prevent repeart call renderCallback. I write a bad code:

.....
    $.fn.extend({
        colorPicker: function(config) {
            var timestamp = new Date().getTime();
            var renderCallback = function(colors, mode) {
                    if(Date.now() - timestamp < 500){
                        return;
                    }else{
                        timestamp = Date.now();
                    }
.....

Is there any good way to solve it?

PitPik commented 8 years ago

Hi @huyinghuan, there is a lot going on when the colorPicker is initialized and therefore renderCallback() gets called multiple times. There is the initialization, the alpha-background gets set, the size of the colorPicker, the memory patches and then the backgroundColor gets saved. All actions that happen on init. Why would you want to prevent the repaint? The behavior is correct. Can you tell me why this bothers you?

Maybe you need to do things inside the actionCallback(). if (action === 'init') will only happen once... Is that what you're looking for?