Thursday, June 6, 2024
 Popular · Latest · Hot · Upcoming
126
rated 0 times [  131] [ 5]  / answers: 1 / hits: 20572  / 12 Years ago, fri, june 29, 2012, 12:00:00

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


More From » svg

 Answers
20

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(',')+);

[#84576] Thursday, June 28, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sherryd

Total Points: 254
Total Questions: 92
Total Answers: 89

Location: Equatorial Guinea
Member since Sun, Feb 14, 2021
3 Years ago
;