I want to be able to send in a few different colors and percentages, as a dynamic length list, to a LESS loop, to create a gradient. At the same time, I'd also like to prepend browser prefixes. The reason for this request is because I'm using CSS gradients in place of graphics for speed and minimizing requests.
Here's how I'm doing it now, but I'd like a more flexible solution:
.mkgrad(@gclrs, @gdir) {
@m:length(@list);
.looppref(@m, @j: 1) when (@j =< @m) {
@mypref: extract(@list, @j);
background:~"@{mypref}-linear-gradient(@{gdir}, @{gclrs})";
.looppref(@m, (@j + 1));
}
.looppref(@m);
.mkdir() when (@gdir = left) {
background:linear-gradient(to right, @gclrs);
}
.mkdir() when (@gdir = top) {
background:linear-gradient(to bottom, @gclrs);
}
.mkdir;
}
I'm calling this with the following:
@str1:fade(@cgray, 50%);
@str2:fade(@cwhite, 50%);
@str3:fade(@cblack, 50%);
@glist:@str1 0%, @str2 30%, @str3 100%;
background:@str3;
.mkgrad(@glist, left);
It's working, but I'd like to be able to merge the @str variables into the above loop so I can just send in a list of colors and percentages, and have it loop the list to build out a string for the background.
Can this be done? Is it possible using a mixin perhaps?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…