varHarrie/varharrie.github.io

Stylus实现迭代生成的Mixin

varHarrie opened this issue · 0 comments

实现

  iterator(from, to, multiple, unit = 1px, prop, abbpre, abbpost = '')
    for i in (from..to)
      .{abbpre}{i * multiple}{abbpost}
        {prop}: i * multiple * unit

使用

  // 使用:
  iterator(0, 5, 5, 1px, height, ui-h)
  
  // 生成出:
  .ui-h0{height:0px}
  .ui-h5{height:5px}
  .ui-h10{height:10px}
  .ui-h15{height:15px}
  .ui-h20{height:20px}
  .ui-h25{height:25px}