mdbassit / Coloris

A lightweight and elegant JavaScript color picker. Written in vanilla ES6, no dependencies. Accessible.
https://coloris.js.org/examples.html
MIT License
443 stars 58 forks source link

How to programmatically change the thumbnail color? #114

Closed Turtleted21 closed 1 year ago

Turtleted21 commented 1 year ago

Hi How to programmatically change the thumbnail color (without a click/pick event)?

I try this without success :

      Coloris({
        el: ".coloris",
        input: "#ff0000",
        wrap: true,
        // swatchesOnly: true,
        alpha: false,
        swatches: ["#264653", "#2a9d8f", "#e9c46a", "#f4a261", "#e76f51", "#48cae4"],
      });

default with a empty value : <input id="color-changer" type="text" class="coloris" value="" style="width: 25px; height: 25px; border-radius: 5px; box-sizing: border-box" />

try to change to pink : document.getElementById("color-changer").dispatchEvent(new Event("input", { value: "#ff00ff" }));

or

document.getElementById("color-changer").value = "#ff00ff";

Thanks