【发布时间】:2017-08-04 08:02:49
【问题描述】:
刚开始学习LESS,看起来和SCSS很像(SCSS = $ & LESS = @)。
但是,从 SCSS 重写后,我似乎无法让 LESS 工作。
我怀疑这与我的循环有关。是我表达我的循环还是百分比方程的方式?
SCSS
body{
background:black;
font-family: 'Varela', sans-serif;
}
.glitch{
color:white;
font-size:100px;
position:relative;
width:400px;
margin: 0 auto;
&:before, &:after{
content:attr(data-text);
position:absolute;
top:0;
color:white;
background:black;
overflow:hidden;
clip:rect(0,900px,0,0);
}
&:before{
left:-2px;
text-shadow:-5px 0 red;
animation:noise-anim 3s infinite linear alternate-reverse;
}
&:after{
left: 2px;
text-shadow: -5px 0 blue;
animation: noise-anim 2s infinite linear alternate-reverse;
}
}
@keyframes noise-anim{
$steps:20;
@for $i from 0 through $steps{
#{percentage($i*(1/$steps))}{
clip:rect(random(100)+px,9999px,random(100)+px,0);
}
}
}
少
https://codepen.io/kangpeter5/pen/mMOyOq
body {
background:black;
font-family: "Varela", sans-serif;
}
.glitch {
color:white;
font-size:100px;
position:relative;
width:400px;
margin: 0 auto;
&:before, &:after{
content:attr(data-text);
position:absolute;
top:0;
color:white;
background:black;
overflow:hidden;
clip:rect(0,900px,0,0);
}
&:before{
left:-2px;
text-shadow: -3px 0 red;
animation:noise-anim 3s infinite linear alternate-reverse;
}
&:after{
left: 2px;
text-shadow: -3px 0 blue;
animation: noise-anim 2s infinite linear alternate-reverse;
}
}
@keyframes noise-anim{
@steps:20;
.loop(@steps, @i:0) when (@i<=@steps){
@keyframeSel: percentage(@i*(1/@steps));
@{keyframeSel}{
clip:rect(random(100)+px, 9999px, random(100)+px,0);
}
.loop(@steps, (@i+1));
}
}
【问题讨论】: