Search code examples
javascriptjqueryspectrumjs

Add double click event


I implemented spectrum color picker, and I am trying to add a double click event to the palettes. (The one that has the predefined colors, the class name is: sp-thumb-el.) I added the following code after line 476:

paletteContainer.on("dblclick", ".sp-thumb-el", function (){
    console.log("you Double Clicked");
});

And nothing happens when I double click. What am I doing wrong and how can I fix it?

Line 479 in JSFiddle


Solution

  • With respect to the comment I made above, you might want to try a hack like this:

           paletteContainer.on("click", ".sp-thumb-el", function (e){
                e.preventDefault();
                e.stopImmediatePropagation();
                                clicks++;
               if(clicks===2){
                 console.log("you Double Clicked");
                 clicks=0;
               } 
            });
    

    The same is updated in your plunkr too..