Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing alpha channel #1

Closed
aiphee opened this issue Jan 19, 2016 · 6 comments
Closed

Missing alpha channel #1

aiphee opened this issue Jan 19, 2016 · 6 comments

Comments

@aiphee
Copy link

aiphee commented Jan 19, 2016

This color picker seems great, except missing option for transparency, would be possible to add a transparency slider?

@NC22
Copy link
Owner

NC22 commented Jan 20, 2016

Ok, so new release here

https://github.com/NC22/HTML5-Color-Picker/releases
see example with enabled slider
test_resize_onchange_event.html

some new enter methods, etc. later will add to wiki

new constructor parameters

alpha - base value for alpha (float value from 0 to 1) default 1
alpha_slider - enable alpha slider (boolean) default false

new events

mouseupalpha
mousemovealpha

new functions

getCurColorRgba - Return array {r : var, g : var, b : var, a : var}
getCurAlpha - Return float alpha value
setAlpha(newAlpha)

@aiphee
Copy link
Author

aiphee commented Jan 20, 2016

Wow, that was fast 👍 Thank you, job well done :)

@aiphee aiphee closed this as completed Jan 20, 2016
@aiphee
Copy link
Author

aiphee commented Jan 21, 2016

Ok, just tried in my project and works great. I just changed updateInput method to change input value accordingly if alpha < 1

function updateInput(){
        if (!input) return;

        if(a < 1) {
            input.value = 'rgba(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ', ' + a.toFixed(2) + ')';
        }  else {
            input.value = hex;
        }

        if (inputColor) {
            if(hsv.v < 0.5){
                input.style.color = "#FFF";
            } else {
                input.style.color = "#000";
            }

            input.style.background = 'rgba(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ', ' + a + ')';
        }
    }

@aiphee
Copy link
Author

aiphee commented Jan 21, 2016

I forked it, not sure if to make pull request since you had many useless space characters which my editor erased.

@NC22
Copy link
Owner

NC22 commented Jan 22, 2016

I'll look that, thanks.

@NC22
Copy link
Owner

NC22 commented Jan 22, 2016

https://github.com/NC22/HTML5-Color-Picker/blob/master/html5kellycolorpicker.js#L806

Your corrections in behavior added. And also added event 'updateinput' for overload private updateInput function if some other behavior is needed.
And yep, I forgot about this useless trailing whitespaces so have to erased them now too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants