本文介绍了是否有可能从更少的CSS中调用具有更少变量的javascript函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
出于定制目的,我必须从较少的CSS调用javascript函数.该函数需要将less变量从更少的文件传递给js.有可能做到吗?使用backtick可以在更少的文件中获取js变量,但是我不知道如何从更少的文件中调用js函数?
I have to call a javascript function from the less css for customization purpose. The function needs to pass the less variable from less file to js. is it possible to do it? using backtick can get js variable in less file but I don't know how to call a js function from less?
demo.js
function getGradient(colorlist, dark, light){
// some large customization
}
demo.less
demo.less
@color: #ffffff,#000000,#cccccc;
@light: 20%;
@dark: 50%;
@gradient : ~`getGradient(@{color}, @{light}, @{dark})`;
上面的代码不起作用.请让我知道是否可以从更少的地方访问js函数?
The above code is not working. Please let me know is it possible to access js function from less?
提前谢谢.
推荐答案
您可以将JavaScript插入带有反引号的lesscss文件中.
You can embed javascript in lesscss files with backticks.
例如:
@myObject: `function(){
var myObject = {
getSomething: function() {
return( "This is yo' content!" );
}
};
return( myObject );
}`;
注意反引号(不是单引号).
这篇关于是否有可能从更少的CSS中调用具有更少变量的javascript函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!