Son04
Son04

Reputation: 321

Is it possible to call a JavaScript function with a Less variable from Less CSS?

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 a 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 a JS function from Less?

Upvotes: 1

Views: 4394

Answers (1)

Don Rhummy
Don Rhummy

Reputation: 25830

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).

Upvotes: 3

Related Questions