I want to ask that If have read that it is possible to give hsl color value to an svg element.But when I try it like this
var color = hsl(0, 100%, 50%);
circle.attr("fill" , color);
I got an error "unexpected number"
Can any one guide what is the correct way and also does svg supports all hsl colors
Thanks
SVG Color Codes To specify an SVG color, you can take Color Names, RGB or RGBA values, HEX values, HSL or HSLA values.
HSL stands for hue, saturation, and lightness. HSLA color values are an extension of HSL with an Alpha channel (opacity).
HSL stands for hue, saturation, and lightness - and represents a cylindrical-coordinate representation of colors. Hue is a degree on the color wheel (from 0 to 360) - 0 (or 360) is red, 120 is green, 240 is blue. Saturation is a percentage value; 0% means a shade of gray and 100% is the full color.
Simply
var color = hsl(0,100%,50%);
line means, that you call hsl
function with 0
,100%
, 50%
parameters, and assign returned value to color
variable.
You need to use quotes, and pass color as a string
:
var color = "hsl(0, 100%, 50%)";
circle.attr("fill" , color);
For more information about HSL
, read here.
And it doesn't metter whether the hsl color is used by SVG
, or by other element. It's just a syntax for specifing color
.
UPDATE: To give color
variable random behavior, try something like this:
var color = "hsl("+[0,0,0].map(function(){ return Math.round(100*Math.random())+"%"; }).join(',')+")";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With