我读过Less#loops和Less#functions docs.但我无法弄清楚如何应用percentage函数或类似的方法来逐步循环百分比而不使用这样的函数.
当我计算它时,如同在另一篇文章中 指出的那样width: percentage(140/620);,它在循环中运行,但在尝试使用变量循环时则不行.
在2014年@pixelass建议使用外部库更容易循环,但我不想使用外部库.
我试图循环(甚至不编译):
.loop (@n, @index: 0) when (@index < @n) {
percentage(@index * (100/@n)){ // This line is messing up my day.
// code
}
.loop(@n, (@index + 1)); // Next iteration.
}
@keyframes anim {
.loop(20); // Launch the loop.
}
Run Code Online (Sandbox Code Playgroud)
我想把这个Sass翻译成Less:
@keyframes anim{
$steps:20;
@for $i from 0 through $steps{
#{percentage($i*(1/$steps))}{
// code
}
}
}
Run Code Online (Sandbox Code Playgroud)