New syntax for creating Color object from Hex/Colorname + Alpha value
Closed this issue · 4 comments
I think there's a need for an additional syntax which allows a hex or named color to be specified along with an alpha value, either as two separate parameters like jQuery.Color( "#abcdef" , 0.5); and jQuery.Color( "aqua" , 0.5); or by specifying an additional sub-parameter like jQuery.Color( "#abcdef, 0.5"); and jQuery.Color( "aqua, 0.5");
Either way, I believe this would be extremely useful when manipulating existing RGB colors entered by users, retrieved from CSS, or obtained from other sources where an alpha value needs to be applied to create an RGBA color.
In comparison, achieving the same thing using the existing syntax is non-obvious and quite longwinded, requiring conversion of the hex RGB / color name into numeric RGBA, changing the Alpha component, and then passing the string as a parameter to jQuery.Color() to obtain the resulting Color object.
Or, just use the .alpha()
setter.... $.Color("aqua").alpha(0.5)
I'm against this one. You could use the .alpha() setter mentioned by gnarf or use rgba() instead.
Though I haven't tested it yet, it seems the [.alpha()] setter is what I needed, thanks - I missed it before, possibly because it's not entirely clear from the examples that it's a setter as well as a getter, as they all talk about "returns..."
Sorry about the unclear documentation there, all of the "getters" are also "setters" like the standard jQuery API pattern