【问题标题】:Stylus empty text variable手写笔空文本变量
【发布时间】:2015-05-28 07:45:53
【问题描述】:

如何创建stylus EMPTY文本变量?

$cross(prop)
  prop = shift(arguments)
  -webkit-{prop} arguments
  -moz-{prop} arguments
  -ms-{prop} arguments
  -o-{prop} arguments
  {prop} arguments

$transition()
  attrs = shift(arguments)
  if length(arguments)
    str = ????WTF???
    for arg in arguments
      if length(str)
        str += \,
      str += arg attrs
    $cross (transition) (str)

我想创建过渡混合:

$transition((.4s ease out), opacity, visibility)

【问题讨论】:

    标签: css stylus


    【解决方案1】:

    不幸的是,length bif 只能用于列表/哈希。它总是为其他节点返回1。你可以这样写:

    $transition()
      attrs = shift(arguments)
      if length(arguments)
        str = ''
        for arg in arguments
          if str != ''
            str += ', '
          str += arg, attrs
        $cross (transition) unquote(str) // unquote to remove quotes
    

    或者你可以编写一个自定义函数来获取字符串长度:

    str-length.js

    module.exports = function() {
      return function(stylus) {
        stylus.define('str-length', function(str) {
          return str.val.length;
        });
      };
    };
    

    test.styl

    use('str-length.js')
    
    $cross(prop)
      prop = shift(arguments)
      -webkit-{prop} arguments
      -moz-{prop} arguments
      -ms-{prop} arguments
      -o-{prop} arguments
      {prop} arguments
    
    $transition()
      attrs = shift(arguments)
      if length(arguments)
        str = ''
        for arg in arguments
          if str-length(str)
            str += ', '
          str += arg attrs
        $cross (transition) unquote(str) // unquote to remove quotes
    
    body
      $transition((.4s ease out), opacity, visibility)
    

    【讨论】:

      猜你喜欢
      • 2015-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-10
      • 2015-06-13
      • 1970-01-01
      相关资源
      最近更新 更多