我甚至不确定如何问这个问题。 LESS CSS框架包含几个操作颜色的函数,我想知道如何自己调用这些函数来修改颜色。问题是,这些功能都位于另一个函数内定义的那样:你怎么称呼less.js功能
(function (tree) {
tree.functions = {
darken: function(color, amount){
...stuff...
}
}
}
我非常清楚,假设变暗是tree.functions的方法,但对我的生活不要”知道如何调用它,因为它是匿名函数(函数(树)。
[编辑] 从@pradeek得到解决后,我创造了这个功能柜面有人需要它的里面。可以轻松适应所有其他的功能少了:
var lessColor = {
/*
|--------------------------------------------------------------------------
| Darken
|--------------------------------------------------------------------------
*/
darken: function(col, val){
col = col.replace(/#/g, ''); //Remove the hash
var color = new less.tree.Color(col); //Create a new color object
var amount = new less.tree.Value(val); //Create a new amount object
var newRGB = less.tree.functions.darken(color, amount); //Get the new color
var hex = (newRGB.rgb[0] + 256 * newRGB.rgb[1] + 65536 * newRGB.rgb[2]).toString(16);
hex = hex.split('.', 1); //Remove everything after the decimal if it exists
//Add padding to the hex to make it 6 characters
while(hex.length < 6){
hex = hex+'0';
}
hex = '#'+hex; //Add the hash
return hex; //return the color
}
}
而且你可以调用它像这样:
$(this).css('background', lessColor.darken($(this).css('background'), .25);
我有同样的问题,我想你的解决方案,但它有不同的输出,你可以在这里回答我的问题? http://stackoverflow.com/questions/22620519/call-less-js-function-in-javascript-has-different-output-in-compare-node – minttux