0

I've created a Javascript expression to evaluate the widths of columns based on some desired folding characteristics I want my grid system to have, but my LESS code gives me a "syntax error". Here is my code:

.setColumnWidths(@maxcolumns, @num_cols, @min_resolution){
    @media screen and(min-width: @min_resolution) {
        .row {
            .onecol {
                width: ~ `Math.min(100%, (100% / {@num_cols}*Math.ceiling({@num_cols}*1/{@maxcolumns})))`;
            }
            .twocol {
            ~ `  Math.min(100%, (100% / {@num_cols}*Math.ceiling({@num_cols}*2/{@maxcolumns})))  `;
            }
            .threecol {
                width: ~ `Math.min(100%, (100% / {@num_cols}*Math.ceiling({@num_cols}*3/{@maxcolumns})))`;
            }
            .fourcol {
                width: ~ `Math.min(100%, (100% / {@num_cols}*Math.ceiling({@num_cols}*3/{@maxcolumns})))`;
            }
            .fivecol {
                width: ~ `Math.min(100%, (100% / {@num_cols}*Math.ceiling({@num_cols}*5/{@maxcolumns})))`;
            }
            .sixcol {
                width: ~ `Math.min(100%, (100% / {@num_cols}*Math.ceiling({@num_cols}*6/{@maxcolumns})))`;
            }
            .sevencol {
                width: ~ `Math.min(100%, (100% / {@num_cols}*Math.ceiling({@num_cols}*7/{@maxcolumns})))`;
            }
            .eightcol {
                width: ~ `Math.min(100%, (100% / {@num_cols}*Math.ceiling({@num_cols}*8/{@maxcolumns})))`;
            }
            .ninecol {
                width: ~ `Math.min(100%, (100% / {@num_cols}*Math.ceiling({@num_cols}*9/{@maxcolumns})))`;
            }
            .tencol {
                width: ~ `Math.min(100%, (100% / {@num_cols}*Math.ceiling({@num_cols}*10/{@maxcolumns})))`;
            }
            .elevencol {
                width: ~ `Math.min(100%, (100% / {@num_cols}*Math.ceiling({@num_cols}*11/{@maxcolumns})))`;
            }
            .twelvecol {
                width: ~ `Math.min(100%, (100% / {@num_cols}*Math.ceiling({@num_cols}*12/{@maxcolumns})))`;
            }
        }
    }
}

The above code will allow "folding", upon calling the mixin:

.setColumnWidths(12, 4, 420px);

Here, we are declaring that the number of columns should be 4, the maximum number of columns is 12, and that this should occur when the screen width is 420px.

Why is this failing, and how can I evaluate these values using javascript otherwise?

1 Answer 1

2

It is a syntax error. The proper syntax for referencing a variable in a JavaScript expression is @{var_name}. You have {@var_name} in the code you posted.

Sign up to request clarification or add additional context in comments.

2 Comments

Tried this, but I'm now getting the following error: JavaScript evaluation error: Math.min(100, ((100 / 4*Math.ceiling(4*1/@{maxcolumns)})))`` So I took out the percentages to make sure it would work... but still no luck. Syntax is like so: .onecol { width: ~Math.min(100, (100 / @{num_cols}*Math.ceiling(@{num_cols}*1/@{maxcolumns}))); }
@user1429980 Try Math.ceil() instead of Math.ceiling().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.