zoukankan      html  css  js  c++  java
  • less封装样式有规律的类选择器-遁地龙卷风

    1.解决的问题

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

    .p2 {
      animation-dely: 0.2s;
       40px;
    }
    .p1 {
      animation-dely: 0.1s;
       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的时候递归调用自己
      前者用于类选择器的输出后者用于样式的输出

  • 相关阅读:
    Linux6
    大小超过2t的分区规划 parted命令
    fdisk命令磁盘分区
    扩展
    磁盘管理
    在Linux中如何手动创建一个用户
    Linux5
    Linux4
    19_权限和分组
    18_django的用户模型和扩展django的用户模型
  • 原文地址:https://www.cnblogs.com/resolvent/p/7082138.html
Copyright © 2011-2022 走看看