在 Spectrum Colorpicker 中取消不起作用

Cancel in Spectrum Colorpicker Not Working

我使用 spectrum.js 颜色选择器仅取消事件不起作用,我必须将颜色重置为初始颜色,因为我正在获取 previewElement null.how 来解决这个问题。

要取消对预览的更改,请使用 events,如下所示:

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 
    }
});

参见example