using javascript calculated values in less

前端 未结 7 1382
无人及你
无人及你 2020-12-18 00:01

In LESS I used following code to get the window\'s height.

@winheight:`$(window).height()`

What I\'m getting is a number, but when i add

相关标签:
7条回答
  • 2020-12-18 00:10

    This might work depending on LESS which I do not know well.

    Reading the docs this is a possibility.

    @winheight:0px + `$(window).height()`
    
    0 讨论(0)
  • 2020-12-18 00:20

    What about this:

    @winheight:`$(window).height().toString() + "px"`
    
    0 讨论(0)
  • 2020-12-18 00:22

    try this

    @winheight:`$(window).height()+"px"`
    height: @winheight;
    

    because .height() returns only unit-less pixel value.
    alternatively use the following

    @winheight:`$(window).css("height")`
        height: @winheight;
    

    .css("height") returns a value with units

    0 讨论(0)
  • 2020-12-18 00:23

    give this code and see what is you get it.

    @winheight:0px + `$(window).height()'
    
    0 讨论(0)
  • 2020-12-18 00:32

    Simply use string interpolation and then escape from the string using ~:

    @winheight:`$(window).height()`;
    
    height: ~"@{winheight}px";
    
    0 讨论(0)
  • 2020-12-18 00:36

    Take .css(height) instead of .height() - this returns the value + unit.

    0 讨论(0)
提交回复
热议问题