Is it possible to call a javascript function with less variable from less css?

落爺英雄遲暮 提交于 2020-05-09 06:54:46

问题


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

@color: #ffffff,#000000,#cccccc;
@light: 20%;
@dark: 50%;
@gradient : ~`getGradient(@{color}, @{light}, @{dark})`;

The above code is not working. Please let me know is it possible to access js function from less?

Thanks in advance.


回答1:


You can embed javascript in lesscss files with backticks.

For example:

@myObject: `function(){

    var myObject = {
        getSomething: function() {
            return( "This is yo' content!" );
        }
    };

    return( myObject );

}`;

Notice the backticks (not single quotes).



来源:https://stackoverflow.com/questions/32621617/is-it-possible-to-call-a-javascript-function-with-less-variable-from-less-css

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!