0

有没有办法在 LESS 中使用正则表达式?这是我的代码:

CSS:

@color: red;

body{color:@color;}/*Text is red if LESS is loaded correctly */

span{display:inline-block;position:relative;top:2px;}

.char1{.titel-animation(0s);}
.char2{.titel-animation(0.2s);}
.char3{.titel-animation(0.4s);}
.char4{.titel-animation(0.6s);}
.char5{.titel-animation(0.8s);}
.char6{.titel-animation(1s);}

.titel-animation(@delay){
    animation: sitetitel 1s @delay ease 1; 
    -moz-animation: sitetitel 1s @delay ease 1; 
    -webkit-animation: sitetitel 1s @delay ease 1;
}

@keyframes sitetitel {
    50%{ 
        color:blue;
    }
}
@-moz-keyframes sitetitel {
    50%{ 
        color:blue;
    }
}
@-webkit-keyframes sitetitel {
    50%{ 
        color:blue;
    }
}​

HTML:

<span class="char1">F</span>
<span class="char2">o</span>
<span class="char3">o</span>
<span class="char4">b</span>
<span class="char5">a</span>
<span class="char6">r</span>

演示:http:
//jsfiddle.net/kaEGh/

我想要的是替换

.char1{.titel-animation(0s);}
.char2{.titel-animation(0.2s);}
.char3{.titel-animation(0.4s);}
.char4{.titel-animation(0.6s);}
.char5{.titel-animation(0.8s);}
.char6{.titel-animation(1s);}

通过这样的事情:

.char@number{.titel-animation(((@number-1) *0.2)s);}

如果可能的话

4

1 回答 1

2

不是正则表达式,但您可以使用守卫来获得递归。我认为以下内容可以满足您的要求....

.charX(@number) when (@number > 0) {
  (~".char@{number}") {
    @adjustedNumber: (@number - 1) *0.2;
    @unitNumber: ~"@{adjustedNumber}s";
    .titel-animation(@unitNumber)
  }
  .charX(@number - 1);
}

.charX(@number) when (@number = 0) {
} 

.charX(6);
于 2012-06-24T11:17:14.740 回答