Skip to content
Advertisement

Cancel in Spectrum Colorpicker Not Working

im using spectrum.js color picker only cancel event is not working on which i have to reset the color to inital one since im getting previewElement null.how to solve this.

Advertisement

Answer

To cancel changes to the preview you have use events like this:

var isChanged = false;
$("#picker").spectrum({
    move : function (tinycolor) {
        // apply the changes to previewElement 
    },
    show : function (tinycolor) {
        isChanged = false;
        previousСolor = tinycolo
    },
    hide : function (tinycolor) {
        if (!isChanged && previousСolor) {
            // revert the changes in the previewElement 
        }
    },
    change : function (tinycolor) {
        isChanged = true;
        // apply the changes to previewElement 
    }
});

See example.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement