我刚刚进入LessCSS,我遇到了我认为是主要的限制,我想知道是否有办法做到这一点?我想说我在某处读到Sass允许用户定义的函数,但LessCSS会做同样的事情吗?
我想做什么:
@fs: 16;
// either return the value
.s(@t,@s,@u) {
// return @t/@s*@u;
}
#elem {
margin-top: .s(30,@fs,1em);
width: .s(900,@fs,1em);
.child {
width: .s(100,900,100%);
}
}
// or have a property argument
.s(@t,@s,@u,@p) {
@{p}: @t/@s*@u;
}
#elem {
.s(30,@fs,1em,margin-top);
.s(900,@fs,1em,width);
.child {
.s(100,900,100%,width);
}
}
Run Code Online (Sandbox Code Playgroud)
我能想出来的唯一方法,但它非常有限,因为我必须有多个mixin:
.s(@t,@s,@u,@p) when (@p = margin-top) { margin-top: @t/@s*@u; }
// margin[-top|-right|-bottom|-left]
// padding[-top|-right|-bottom|-left]
.s(@t,@s,@u,@p) when (@p = width) { width: @t/@s*@u; }
.s(@t,@s,@u,@p) when (@p = height) { height: @t/@s*@u; }
Run Code Online (Sandbox Code Playgroud)
我知道我总是可以修改less.js文件来添加一个像内置函数 …
我有一个问题,并想知道是否有人可以给我一些关于原因的见解.以下代码正在向一个日期添加一周:
while (c.getStamp() < b.getStamp()) {
var f = this.getWeek(c);
e.push(f);
c = (c.getStamp() + 604800).toDate();
}
...
Date.prototype.getStamp = function() {
return Math.round(this.getTime() / 1e3);
};
Number.prototype.toDate = function() {
return new Date(this * 1e3);
};
Run Code Online (Sandbox Code Playgroud)
我试图让以下工作,但它创建一个连续循环:
while (c.getStamp() < b.getStamp()) {
var f = this.getWeek(c);
e.push(f);
c = new Date(c.getFullYear(), c.getMonth(), c.getDate + 7, 0, 0, 0);
}
Run Code Online (Sandbox Code Playgroud)
哪里c = JS Date, ie 05/01/12和b = JS Date, ie 05/31/12
我收到以下错误,我似乎无法弄清楚为什么或如何触发它.
Fatal error: Cannot access empty property in /home/content/p/l/a/plai1870/html/com/php/Bone/Compiler.php on line 18
第18行是
throw new LogicException($this->$compilers[$language]." is not a supported compiler.");
Run Code Online (Sandbox Code Playgroud)
这是Compiler.php
<?php
namespace Bone;
use LogicException;
class Compiler implements \Bone\Interfaces\Compiler {
protected $compiler;
protected $compilers = array(
"php" => "PHP",
"as3" => "ActionScript3",
"javascript" => "Javascript"
);
public function __construct($language) {
$language = strtolower($language);
if (!isset($this->$compilers[$language])) {
throw new LogicException($this->$compilers[$language]." is not a supported compiler.");
}
$compiler = "\Bone\Compilers\\".$this->$compilers[$language]."\Compiler";
$this->compiler = new $compiler();
}
public function buildDefinition($object, $path = …Run Code Online (Sandbox Code Playgroud)