Giter VIP home page Giter VIP logo

Comments (7)

mdbassit avatar mdbassit commented on June 23, 2024

I believe you are setting the value of #clr-color-value before the color picker is properly initialized. Try this :

Coloris({
    parent: '#e-color-picker',
    alpha: true,
    theme: 'large',
    format: 'mixed',
    inline: true
});

const setColorToGreen = () => {
    document.querySelector('#clr-color-value').value = 'green';
    document.querySelector('#clr-color-value').dispatchEvent(new Event('change', { bubbles: true }));
};

document.addEventListener('coloris:pick', event => {
    console.log('New color', event.detail.color);
});

// Wait for the document to load first
if (document.readyState !== 'loading') {
    setColorToGreen();
} else {
    document.addEventListener('DOMContentLoaded', function () {
        setColorToGreen();
    });
}

from coloris.

mdbassit avatar mdbassit commented on June 23, 2024

Also, if all you need is to set the default color of the inline picker, just use the defaultColor option:

Coloris({
    parent: '#e-color-picker',
    alpha: true,
    theme: 'large',
    format: 'mixed',
    inline: true,
    defaultColor: 'green'
});

from coloris.

VelinGeorgiev avatar VelinGeorgiev commented on June 23, 2024

@mdbassit thanks for your response. I don't believe the issue is with setting the defautl value. I get the same result even by just using the basic initializaiton and nothing elsle.

Coloris({
    parent: '#e-color-picker',
    alpha: true,
    theme: 'large',
    format: 'mixed',
    inline: true,
    defaultColor: 'green'
});

In my case when I try to select a color, the cursor position does not get updated. Awlays stays x=0, z=0, however 'coloris:pick' events still get fired.

from coloris.

mdbassit avatar mdbassit commented on June 23, 2024

That's quite strange! I'm unable to reproduce the issue, but it's likely that something is interfering with the calculation of the position of the mouse pointer. Can you maybe share the rest of your code or the link to a page where I can take a look at this in action?

from coloris.

VelinGeorgiev avatar VelinGeorgiev commented on June 23, 2024

Thanks @mdbassit ! I will try to debug the comming days and share a better example if I am unable to make it work.

from coloris.

VelinGeorgiev avatar VelinGeorgiev commented on June 23, 2024

Ok, I managed to make it work on a clear page.

Here are examples in case someone is interested.

<html>
    <body style="margin: 0;padding: 0;">

        <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/mdbassit/Coloris@latest/dist/coloris.min.css"/>
        <script src="https://cdn.jsdelivr.net/gh/mdbassit/Coloris@latest/dist/coloris.min.js"></script>
       
        <div style="display: flex; justify-content: center; align-items: center;height: 100%;">
            <div id="e-color-container" style="border: 1px solid #000;position: relative;height: 400px;width: 400px;"></div>
        </div>

        <script>
            document.addEventListener('DOMContentLoaded', () => {
                Coloris({
                    parent: '#e-color-container',
                    inline: true,
                    alpha: true,
                    theme: 'large',
                    format: 'mixed',
                    defaultColor: '#fff'
                });

                document.addEventListener('coloris:pick', event => {
                    console.log('New color', event.detail.color); 
                });
            });
        </script>
    </body>
</html>

and Preact

<html>
    <body style="margin: 0;padding: 0;">

        <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/mdbassit/Coloris@latest/dist/coloris.min.css"/>
        <script src="https://cdn.jsdelivr.net/gh/mdbassit/Coloris@latest/dist/coloris.min.js"></script>

        <script type="module">
            import { html, Component, render, useEffect } from 'https://unpkg.com/htm/preact/standalone.module.js';
          
            function App (props) {

                useEffect(() => {

                    Coloris({
                        parent: '#e-color-container',
                        inline: true,
                        alpha: true,
                        theme: 'large',
                        format: 'mixed',
                        defaultColor: '#fff'
                    });

                }, [])

              return html`
                <div style="display: flex; justify-content: center; align-items: center;height: 100%;">
                    <div id="e-color-container" style="border: 1px solid #000;position: relative;height: 400px;width: 400px;"></div>
                </div>
              `;
            }
          
            render(html`<${App} />`, document.body);
        </script>
    </body>
</html>

Thanks!

from coloris.

VelinGeorgiev avatar VelinGeorgiev commented on June 23, 2024

Will close the thread. Thanks!

from coloris.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.