2013-08-20 216 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; 
} 

當然,如何構建更復雜的混合函數有許多不同的方法,但解決方案/方法將取決於您在特定情況下想要達到的目標。