10
09/2014
less variables use array
I want set random color to sth use lesscss.
@colorArr:'#00c,red,green'; .random_color(@arg){ background-color:~`@{colorArr}.split(',')[@{arg}]`; } .random_color(){ @len:`Math.floor(Math.random()*(@{colorArr}.split(',').length))`; background-color:~`@{colorArr}.split(',')[@{len}]`; } .div1 { height:300px; .random_color(); .random_color(0); }
- use .random_color() to generate random color.
- .random_color(N) get the N-index of colorArr.