在LESS中使用正则表达式

时间:2012-06-24 10:25:19

标签: css regex css3 less css-animations

有没有办法在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);}

如果可能的话

1 个答案:

答案 0 :(得分: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);