A
A
Alexey Pavlov2018-04-19 17:24:17
css
Alexey Pavlov, 2018-04-19 17:24:17

How to get around restrictions when using recursion in less*?

Just tell me if it's possible to get around the recursion restrictions. If so, how?
*On codepen:

@num: 1;
.mixin() when (@num =< 100) {
  #square-@{num} {
    animation-delay: @num;
  }
  @num: @num + 1;
}
  .mixin();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Radkov, 2018-04-19
@paulradzkov

https://codepen.io/paulradzkov/pen/vjEdbM
Instead of recursively defining a variable, we call the mixin recursively:

@num: 100;
.mixin(@num) when (@num > 0) {
  .mixin(@num - 1);
  [email protected]{num} {
    animation-delay: @num;
  }
}
.mixin(@num);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question