Answer the question
In order to leave comments, you need to log in
How to implement dynamic variables in LESS loop?
Good day everyone.
The essence of the problem: there is an icon sprite generated with the help of spritesmith (I use gulp). The final file is a less file with all the necessary variables and mixins. Example:
@rss-name: rss;
// ... еще много подобных параметров ...
@rss: 24px 48px -24px -48px 24px 24px 93px 72px '../images/sprite.png' rss;
// ... опустим второстепенные миксины ...
.sprite(@sprite) {
.sprite-image(@sprite);
.sprite-position(@sprite);
.sprite-width(@sprite);
.sprite-height(@sprite);
}
@icon-list: @twitter-name, @rss-name;
.icon-loop(@index: 1) when (@index <= length(@icon-list)) {
@item: extract(@icon-list, @index);
[email protected]{item} {
.sprite(@{item}); // Внимание на эту строчку - тут должна произойти магия
}
.icon-loop(@index + 1);
}
.icon-loop();
Answer the question
In order to leave comments, you need to log in
I won't say anything about LESS.
I also use spritesmith, but only for sass.
I do this in sass
$icons-list: 'vk', 'email', 'map', 'link', 'phone';
@each $icons in $icons-list {
.b-icon_img_#{$icons} {
@include sprite($icons);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question