2013-08-20 132 views
0

当我使用默认less.js我可以在一个函数中返回一个变量,如:lessphp - 一个函数返回变量

.function(@x,@y) { 

    .innerFunction() when (@x = @y) { 
    @output: @x 
    } 

    .innerFunction() when not (@x = @y) { 
    @output: @x/10; 
    } 

    .innerFunction() when (...) { 
    @output: @x + @y; 
    } 

    property: @output; 

} 

这是非常实用的,以创建更复杂的功能较少,但它不工作lessphp ...有没有办法在Lessphp中返回变量?

回答

0

Lessphp不允许变量泄漏出定义规则的范围。

lessphp documentation这样说:

变量只能从他们目前的范围,或任何 封闭范围使用可见。

,你可以重新格式化一个mixin这样在两个less.js工作,lessphp可能是沿着这些线路的东西的方式:

.function(@x,@y) { 
    .innerFunction() when (@x = @y) { 
    .output(@x); 
    } 
    .innerFunction() when not (@x = @y) { 
    .output(@x/10); 
    } 
    .output(@output) { 
    property: @output; 
    }; 
    .innerFunction(); 
} 

和例如调用像这样的mixin中LESS:

.test-class { 
    .function(20,11); 
} 

会给你下面的CSS:

.test-class { 
    property: 2; 
} 

当然,如何构建更复杂的混合函数有许多不同的方法,但解决方案/方法将取决于您在特定情况下想要达到的目标。