【问题标题】:Rewriting SCSS to LESS将 SCSS 重写为 LESS
【发布时间】: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));
    }
}

【问题讨论】:

    标签: css sass less


    【解决方案1】:

    您的 less 文件中有几个错误,但我必须向您保证,只有当您仔细阅读红色文档时,才能解决所有问题;)因为我不明白您为什么要从 scss 切换到 less,即使我更喜欢无论如何,他们都做同样的事情,即使它们有不同的优点和缺点,我仍然想帮助你,并解释你在 codepen 上的代码有什么问题。

    首先,我检查了你的编译代码,发现你的循环根本没有输出,所以我做的第一件事就是在某个地方添加了第一个执行来启动循环,因为它被声明了,但没有启动.然后我看到你正在使用更少的 random(100) mixin,所以只是模拟了它,放到变量中,看起来它现在正在工作:)

    @keyframes noise-anim{
      @steps:20;
      .loop(@steps, @i:0) when (@i=<@steps){
        @keyframeSel: percentage(@i*(1/@steps),~'%');
        @{keyframeSel}{
          @rand1: ~"`Math.random()*100`px";
          @rand2: ~"`Math.random()*100`px";
          clip:rect(@rand1, 9999px, @rand2,0);
        }
        .loop(@steps, (@i+1));
      }
      .loop(@steps);
    }
    

    希望对你有帮助。

    【讨论】:

    • 谢谢 Maciej。我最近得到了一个新的演出,他们使用 LESS(我之前对 SCSS 有点熟悉)。
    猜你喜欢
    • 2014-12-18
    • 2017-11-29
    • 1970-01-01
    • 1970-01-01
    • 2018-11-23
    • 2015-02-12
    • 1970-01-01
    • 2016-01-07
    • 2013-05-10
    相关资源
    最近更新 更多