我的html中有这个:
<script type="text/javascript">
less = {
env: "development", // or "production"
async: false, // load imports async
fileAsync: false, // load imports async when in a page under
// a file protocol
poll: 1000, // when in watch mode, time in ms between polls
functions: {
returnCenter: function (value, context) {
return 'center';
}
}, // user functions, keyed by name
dumpLineNumbers: "comments", // or "mediaQuery" or "all"
relativeUrls: false,// whether to adjust url's to be relative
// if false, url's are already relative to the
// entry less file
rootpath: ":/a.com/"// a path to add on to the start of every url
//resource
};
</script>
<script src="less.js" type="text/javascript"></script>
所以在函数中,如何在less文件中创建和使用函数?
谢谢,祝你好运!
Pd积。这个returnCenter不起作用。有或没有参数。
答案 0 :(得分:0)
出于某种原因,您应该用小写编写函数名称。你的函数也应该返回一个合适的类型。
尝试:
<script>
less = {
env: "development",
functions: {
returncenter: function(context, value) {
return new(less.tree.Anonymous)('center');
}
}
};
</script>
现在您可以使用以下Less代码:
selector {
property: returncenter();
}
前面的Less代码将编译成以下CSS代码:
selector {
property: center;
}