当我使用默认的less.js时,我可以在函数中返回一个变量,如下所示:
.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中返回变量?
发布于 2013-09-03 05:46:46
Lessphp不允许变量泄漏到定义它们的规则范围之外。
这样说:
变量仅在其当前作用域或任何封闭作用域中可见。
重新格式化这样的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();
}例如,在LESS中像这样调用mixin:
.test-class {
.function(20,11);
}将为您提供以下CSS:
.test-class {
property: 2;
}当然,如何构建更复杂的mixins有许多不同的方法,但解决方案/方法将取决于您在特定情况下到底想要实现什么。
https://stackoverflow.com/questions/18335952
复制相似问题