less封装样式有规律的类选择器-遁地龙卷风

1.解决的问题

.class-rule(p,2,width 20px animation-dely 0.1s);可以生成下列css样式

.p2 {
  animation-dely: 0.2s;
  width: 40px;
}
.p1 {
  animation-dely: 0.1s;
  width: 20px;
}

2.less 代码

.class-rule(@name,@number,@rest) when(@number > 0){
	
	@max-index:length(@rest) / 2;
	.@{name}@{number}{
		.setAttribute(@max-index,@number,@rest,@name);	
	}
	.class-rule(@name,@number - 1,@rest);
	.setAttribute(@index,@number,@rest,@name) when(@index > 0){

		@initialValue:extract(@rest,(@index - 1) * 2 + 2);
		@attribute:extract(@rest,(@index - 1) * 2 + 1);
		@{attribute}:@initialValue * @number;
		.setAttribute(@index - 1,@number,@rest,@name);
	}
}

  .class-index(p,3,animation-delay 0.1s );
  .class-index(p,3,animation-delay 0.1s width 20px);
  *@number 需大于1
  animation-delay 0.1s
  这样的参数会被认为是一个列表,列表中有两个元素,下标从1开始
  .class-rule和.setAttribute都会在第二个参数大于0的时候递归调用自己
  前者用于类选择器的输出后者用于样式的输出

 

转载于:https://www.cnblogs.com/resolvent/p/7082138.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值