代码之家  ›  专栏  ›  技术社区  ›  Miguel Morera

在触针混音器中串联变量

  •  0
  • Miguel Morera  · 技术社区  · 8 年前

    centerSprite($icon)
        margin-top -(($ico_+$icon+_height) / 2)
        margin-left -(($ico_+$icon+_width) / 2)
    

    我有一个具有图标高度和宽度的变量,我想将名称放入mixin的参数中,以获取该变量并进行操作。。。

    2 回复  |  直到 8 年前
        1
  •  0
  •   user4994625 user4994625    8 年前

    我不知道为什么(可能是虫子?)但是,当函数中的属性值中有一个前减括号时,stylus无法编译:

    centerSprite()
        margin-top -((5 + 10 + 3) / 2)
    
    body
        centerSprite()
    

    但是这个没有函数编译:

     body
         margin-top -((5 + 10 + 3) / 2)
    

    我发现如果在属性在函数中也起作用后使用冒号:

    触笔

    centerSprite()
        margin-top: -((5 + 10 + 3) / 2)
    
    body
        centerSprite()
    

    CSS

    body {
        margin-top: -9;
    }
    
        2
  •  0
  •   Miguel Morera    8 年前

    一个好人 on Github 向我解释了 lookup

    $ico_test_width  ?= 20px
    $ico_test_height ?= 15px
    
    centerSprite($icon)
        margin-top : -(lookup('$ico_' + $icon + '_height') / 2)
        margin-left: -(lookup('$ico_' + $icon + '_width')  / 2)
    
    body  
        centerSprite('test')