Closed CommanderRaiker closed 1 year ago
I assume you are using this as part of a Chrome extension. You will need to use a throttling technique to avoid that error. I will not be changing the behavior of onChange
. Here is an example of throttling using setTimeout
:
// This will store a timer id
let timeOut;
// Configure Coloris (or a Coloris instance)
Coloris({
el: '.coloris',
onChange: color => {
// Abort if setTimeout has already been called
if (timeOut) {
return;
}
// Schedule an action after 1 second delay
timeOut = setTimeout(() => {
// Call your custom function after the delay
mySaveFunction();
// Set the timer id to undefined to mark the scheduled action as finished
timeOut = undefined;
}, 1000);
}
});
Hi,
I implement your code with the parameter
onChange
so I can save a selected color after selection. Unfortunately the event fires multiple times when clicking an holding the mouse button to move around the color palette to choose a color. Is it possible, that theonChange
Even only fires onmouseup?Otherwise I think this color picker is very nice. You done a very nice job.